Data Structure (2130702)

BE | Semester-3   Summer-2016 | 06/09/2016

Q2) (a)

Write an algorithm for simple queue with ENQUEUE operations.

Procedure: QINSERT_REAR (Q, F, R, N,Y)
Given F and R pointers to the front and rear elements of a queue respectively. Queue Q consisting of N elements. This procedure inserts Y at rear end of Queue.
1. [Overflow]
 IF R >= N
 Then write (‘OVERFLOW’)
 Return
2. [Increment REAR pointer]
 R <-- R + 1
3. [Insert element ]
 Q[R] <-- Y
4. [Is front pointer properly set]
 IF F=0
 Then F <-- 1
 Return