Docsity

C Implementation of Circular Queues using Doubly-Linked List for ECE 329 Project - Prof. S, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 329 Project 1/4
Programming Assignment 1 - Queues
Write a C module that implements circular queues using a doubly-linked list.
The code should contain the following interface and functions:
// 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 ptrData2
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
pf3
pf4

Partial preview of the text

Download C Implementation of Circular Queues using Doubly-Linked List for ECE 329 Project - Prof. S and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Programming Assignment 1 - Queues

Write a C module that implements circular queues using a doubly-linked list.

The code should contain the following interface and functions:

// 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);

Your test harness module should have the format shown below:

#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; }