- Use an implementation file queue.c and a
header file queue.h, along with a program to
test the queue queue_test.c.
- Use linked lists for the implementation in
queue.c, but there should be no way to know
the method of implementation from outside this file.
- I suggest that you use two pointers to list nodes:
front and rear to represent
the queue itself. An empty queue might be signified by
the initial condition front == NULL.
(It is permissible to determine an empty queue in a different
way if you want.)
- Items are inserted in the queue at the rear, so that
in the picture below, the character 'd'
was the last item inserted. Items are removed from the queue
at the front, so 'a' would be the next item
removed from the queue below.
- In case of a deletion, the storage for the node should
be freed.
- You should check for underflow, that is, attempting
to remove an item from an empty queue.
- You can partly model your code after the linked list
stack above. You will probably need to handle insertion
into an empty queue as a special case.
- As in the stack above, you should check whether
the malloc function fails to get storage,
signalled by returning a null pointer. (In practice, we
would not expect this to happen.)
|