Write a generic queue in C using a "void *" implementation. The
implementation should use an array to hold the queue elements. Use
a "circular" implementation that wraps the end of the queue around to the front of
the array once it reaches the end of the array. Your implementation will
need to keep track of two indices--one that points to the front of the
queue and one that points to the end of the queue. If you have the Scott
text, you can look at Figure 8.4 on page 413 to get an idea of the
implementation I want.
The API that you will implement is:
void *queue_new(int numItems); // create a queue that can hold the indicated number of items
void queue_enqueue(void *q, void *item); // add the element to the back of the queue
void *queue_dequeue(void *q); // remove and return the element at the front of the queue
int queue_isEmpty(void *q); // 1 if empty and 0 otherwise
I have included several files for this problem:
If you have questions about what your output should look like, I have
placed a C executable of queueDriver in /home/bvz/cs365/hw/hw5.
- queueDriver.c: the driver program
- queue.h: the .h file you should use. Notice that it does not
contain a struct for queue. You should place your queue struct into queue.c
so that you achieve information hiding. If you are confused about how to
do information hiding in C, then re-watch my video on Modules-C-C++ or
look at my notes about modules in C and C++.
- queueInput: some sample input. You should test your program
with other input, but do not worry about bad input, input that overflows
the queue, input that tries to access an empty queue, etc.