August
1997 QUESTION 5 Total Marks: 20 Marks |
Click here to access other
questions
Click to access |
5. | (a) Identify and explain the difference between a stack and queue abstract data-type. | [2] | |
(b) Given the following type definition for a queue: | |||
Where Front points to the first element in the queue and Rear points to the last element added to the queue. It is assumed that the Next field of a Node points from newer elements in the queue to older ones. | |||
(i) Write a function sizeQueue that takes a queue of type QueueType as its argument, and returns an integer that identifies the number of elements in the queue. | [5] | ||
(ii) Write a procedure enQueue that takes two arguments: (i) a queue of type QueueType; and (ii) an integer to be added to the queue. The effect of the procedure is to alter the queue argument by adding the integer parameter to the queue. | [6] | ||
(iii) Write a procedure deQueue that takes a non-empty queue of type QueueType as its argument. The effect of the procedure is to alter the queue by removing an element. | [7] |