User Tools

Site Tools


notes:data:fall2023:projects:waq0

This is an old revision of the document!


Queue

While stacks followed LIFO (last in first out) queues follow FIFO (First in First out).

Queue Struct

Here is a simple struct you can implement for your queue structure:

struct queue {
    cardnode* front;  // Pointer to the front of the queue
    cardnode* rear;   // Pointer to the rear of the queue
    int size;         // Size of the queue
};

The provided struct consists of a front and rear pointer of a queue along with a size variable.

Function to initialize Queue

Once you have created your struct for your queue you can optionally create a function to call every time you want to make a queue. If you are creating the card game War(highly recommended) this is not necessary but helps clean up your program.

Here is an example of a function that creates a queue:

// Function that creates and initializes a new deck structure
deck* createDeck()
{
    deck* newDeck = (deck*)malloc(sizeof(deck));
    newDeck->start = NULL;
    newDeck->end = NULL;
    newDeck->size = 0;
    return newDeck;
}
notes/data/fall2023/projects/waq0.1699237718.txt.gz · Last modified: 2023/11/06 02:28 by wgates1