You must implement the enqueue
and dequeue
functions of a Queue that is implemented as a simple circular list. This
Wikipedia page describes such a list as follows:
"With a circular list, a pointer to the last node gives easy access also to the first node, by following one link. Thus, in applications that require access to both ends of the list (e.g., in the implementation of a queue), a circular structure allows one to handle the structure by a single pointer, instead of two."
Assume that the head of the queue is the leftmost node and that the tail of the queue is the rightmost node. In the previous example, the head and the tail are respectively 12
and 37
. So in this case, the only pointer you can use will point to the 37
node.
You can use the following datastructures for this exercise:
typedef struct node{ struct node* next; int value; } node_t; typedef struct queue{ struct node* tail; int size; } queue_t ;