Suppose a circular queue of capacity $(n −1)$ elements is implemented with an array of $n$ elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are (A)
full: (REAR+1) mod n == FRONT
empty: REAR == FRONT$
(B)
empty: (FRONT+1) mod n == REAR
(C)
full: REAR == FRONT
empty: (REAR+1) mod n == FRONT
(D)
full: (FRONT+1) mod n == REAR
empty: REAR == FRONT
rear = Write
front = Read
Only option A matches.
No. FRONT will be pointing to the first item in the queue, while REAR will be pointing to the next empty location.
See this :
D -> This is incorrect, because if you have two elements in Queue of size 5, Front + 1 will not point to Rear. full: (FRONT+1) mod n == REAR is incorrect.
C-> full: REAR == FRONT This is wrong part. Even initially we had rear = front = 0 , does this means queue is full ?
B-> empty: (FRONT+1) mod n == REAR , Initially queuee is empty, still this heuristic will say that queue is not empty. As Rear = front = 0, So Front + 1 % mod n = 1 != 0
A is correct option.
4386 Points
2464 Points
1850 Points
1686 Points
1340 Points
1184 Points
1112 Points
1080 Points
900 Points
732 Points
Gatecse
hi, but according to this post
Nice Post.Thanks,