This is an old revision of the document!
If Stacks don't quite fit the design for what you're coding, you may want to consider a Queue instead.
Queues are similar in structure to Stacks with a different functionality. Both data structures exist overtop a List of some kind (for our instance it'll be a doubly-linked list).
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.
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 queue queue* createQueue() { queue* newQueue = (queue*)malloc(sizeof(queue)); newQueue->front = newQueue->rear = NULL; newQueue->size = 0; return newQueue; }