//Assignment # 4 Question 1 //Due Oct 14,1999 Conditions necessary and sufficient for a sequence of insert and remove operations on a single: 1a) Empty queue to leave the queue empty without causing underflow: ------------------------------------------------------------------ 1) One of the location in queue is reserved and is never filled. Queue Locations: 0 1 2 3 4 5 Items in Queue: A 2) The front pointer points to a position one less than the acutal element in queue. Queue Locations: 0 1 2 3 4 5 Items in Queue: ABCDE Front Pointer:0 Rear Pointer:5 3) With above two conditoins. Front = Rear only if no elements are present in the Queue. This condition indicates Empty queue. All deQueue operations must see if front=rear before dequeueing. 1b) Conditions to leave non-empty queue unchanged: ------------------------------------------------------ Consider a queue implemented using Array with MAX = 4 Queue Slots : 0 1 2 3 Items in Queue: A B C Front=0 Rear=3 Here Rear=MAX-1 element. Addition of another item will result in operation rear=0. Front must be checked before this operation as rear=front=0 will render empty queue.