// Implementation of the Queue ADT using a linked list #include #include #include #include "Queue.h" // DO NOT modify these structs struct node { Item item; struct node *next; }; struct queue { struct node *head; struct node *tail; int size; }; /** * Creates a new empty queue */ Queue QueueNew(void) { Queue q = malloc(sizeof(*q)); if (q == NULL) { fprintf(stderr, "couldn't allocate Queue\n"); exit(EXIT_FAILURE); } q->head = NULL; q->tail = NULL; q->size = 0; return q; } /** * Frees all resources associated with the given queue */ void QueueFree(Queue q) { struct node *curr = q->head; while (curr != NULL) { struct node *temp = curr; curr = curr->next; free(temp); } free(q); } /** * Adds an item to the end of the queue */ void QueueEnqueue(Queue q, Item it) { // TODO } /** * Removes an item from the front of the queue and returns it * Assumes that the queue is not empty */ Item QueueDequeue(Queue q) { // TODO return 0; } /** * Gets the item at the front of the queue without removing it * Assumes that the queue is not empty */ Item QueueFront(Queue q) { assert(q->size > 0); return q->head->item; } /** * Gets the size of the given queue */ int QueueSize(Queue q) { return q->size; } /** * Returns true if the queue is empty, and false otherwise */ bool QueueIsEmpty(Queue q) { return q->size == 0; } /** * Prints the items in the queue to the given file with items space-separated */ void QueueDump(Queue q, FILE *fp) { for (struct node *curr = q->head; curr != NULL; curr = curr->next) { fprintf(fp, "%d ", curr->item); } fprintf(fp, "\n"); } /** * Prints out information for debugging */ void QueueDebugPrint(Queue q) { }