


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



// Opaque type for a circular queue *typedef void TCircularQ; // Return a new queue “object” TCircularQ Q_New(void); // Add an item to the TAIL of the queue *int Q_AddToTail(TCircularQ q, void ptrData); // Inserts a Node (ptrData1) AFTER the node pointing to ptrData **int Q_InsertItemAfter(TCircularQ q, void ptrData1, void ptrData2); // Inserts a Node (ptrData) AFTER the nth node (0 to MAX-1) *int Q_InsertItemAfterNthItem(TCircularQ q, int n, void ptrData); // Remove the head item from the queue int Q_RemoveHead(TCircularQ q); // Remove an item from the queue which has the data ptrData *int Q_RemoveItem(TCircularQ q, void ptrData); // Remove an nth item from the queue int Q_RemoveNthItem(TCircularQ q, int n); // Return the (address of the data of) HEAD item of the queue *void Q_Head(TCircularQ q); // Return the (address of the data of) TAIL item of the queue *void Q_Tail(TCircularQ q); // Return the (address of the data of) nth item of the queue *void Q_nthItem(TCircularQ q, int i); // Move HEAD to TAIL and return (address of the data of) new HEAD *void Q_Next(TCircularQ q); // Return the current number of items in the queue int Q_Items(TCircularQ q); // Return address of (data of) previous node of the nth of Queue *void Q_AddressOfPreviousNode(TCircularQ q, int n); // Returns address of (data of) next node of the nth node of Queue *void Q_AddressOfNextNode(TCircularQ q, int n); // Delete queue (frees memory and makes pointer NULL) *int Q_Delete(TCircularQ q); // Print the current error for queue
void Q_PrintError(void);
#include <stdio.h> ... #include "queues.h" ... int main(void) { ... TCircularQ Q1; ... // *** Initialize a Q *** // printf("Initialize First Q\n"); if ((Q1 = Q_New()) == NULL) Q_PrintError(); ... printf("Delete First Q\n"); if ( Q_Delete(&Q1) < 0 ) Q_PrintError(); return 0; }