Group 1: MakeEmptyQueue and Enqueue
- Recall:
- A 'Queue' is a 'First-In-First-Out' list where you insert new elements at the tail and
remove existing elements from the head. The operations on a queue are MakeEmptyQueue,
Enqueue, Serve, IsEmpty, IsFull.
- Your Task:
- Impelement the MakeEmptyQueue and the Enqueue procedures, as detailed
below. Start with the MakeEmptyQueue procedure, which is basically only two lines.
Then discuss the Enqueue routine, which is a little more complicated. When you are
done, post both routines as two seperate postings on our bulletin board and we will
discuss the routines together.
- Details:
- You have 15 minutes to come up with the two routines. Select one person as speaker of
the group. When you have come up with your answer, the speaker should post the solutions
on the bulletin board. Each of you might want to bring up Notepad for taking notes,
if you like.
StdElement = Char;
NodePointer = ^Node;
Node = Record
Data: StdElement;
Next: NodePointer;
end;
Queue = Record
Head, Tail : NodePointer;
end;
procedure MakeEmptyQueue(var Q: Queue);
{ PRE: none }
{ POST: Creates a valid, empty queue }
procedure Enqueue(var Q: Queue; el: StdElement);
{ PRE: The queue is not full }
{ POST: Q includes el as its most recently arrived element }