Group 2: IsEmpty, IsFull, Serve
- 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 IsEmpty, the IsFull, and the Serve procedures, as
detailed below. Start with the IsEmpty and IsFull functions, both of which
are basically only one line. Then discuss the Serve routine, which is a little more
complicated. When you are done, post all three routines as three seperate postings on our
bulletin board and we will discuss the routines together.
- Details:
- You have 15 minutes to come up with the three 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 as three seperate postings. 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;
function IsEmpty(Q: Queue): boolean;
{ PRE: none }
{ POST: If the queue is emtpy, returns true, else returns false }
function IsFull(Q: Queue): boolean;
{ PRE: none }
{ POST: If the queue is full, returns true, else returns false }
procedure Serve(var Q: Queue; var el: StdElement);
{ PRE: The queue is not empty }
{ POST: The least recently arrived (i.e. the 'oldest') element is removed }
{ from the queue, and returned in el }