The goal of this project is to practice using pointers for programming in C.
In this project, you will be doing something familiar (implementing queues two ways: with an array and as a linked list) in a manner unfamiliar (using dynamic arrays and pointers in C). You will be writing two library files (each with both a header and source file) to implement queues. In either case, you will write a struct that represents the queue itself and a series of functions which provide the behavior of the queue.
Copy the driver program
cp /cslab.all/ubuntu/cs245/proj7/queuedriver.c .
First, open the driver program and look it over. You'll see that it expects the following things:
arrayqueue.h
or listqueue.h
.
You will write both, and you can test them alternately by commenting out
and un-commenting the relevant lines.
ArrayQueue
or ListQueue
.
This will have to be a struct type.
makeQueue()
function
which takes an integer indicating a maximum size for the queue
and returns a pointer to a newly allocated queue.
The list queue can ignore the maximum size (it can grow unbounded).
offer()
,
poll()
, and peek()
, but notice that
these take a pointer to the queue as a parameter--- they can't be
like instance methods.
destroyQueue()
,
which deallocates the queue.
Then, write the two libraries. Remember what we learned about how to compile and link. Be careful on your use of pointers and your allocating and deallocating.
Write and use a makefile
for managing this
project.
Not only will this be a convenience for you; it also is a
requirement of the project.
Turn in a hard copy of a typescript showing all files you edited (including the makefile). Compile and run both versions. For the array version, run your program twice, once where the user enters data until the queue is full, and the other where the user quits by entering -1.
DUE:Wed, Apr 28, 5:00 pm.