The Gateway to Computer Science Excellence
0 votes

Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements.

Now, in this queue what will be condition for FULL and EMPTY?

Full:(REAR+1)%n== FRONT






 Empty:   FRONT==REAR


              REAR== FRONT


I think FRONT== REAR and REAR==FRONT means same, So, both will give correct result in case of Empty . It is a checking if both pointer pointing same or not. But for FULL it will not give correct result. because, Rear cannot go same location as Front locating . But Front pointer can come and point same location as rear.

So, in case of Full, Rear point array that must be array index more than Front

Am I right?

Then what equation will valid?



in Programming by | 241 views
i think for full : (rear+1)mod n ==front       for empty: both as you mentioned.
FRONT==REAR or REAR==FRONT are INDEED same, how can they even be doubted?

Yes, in circular queue, the condition for empty queue is IF(REAR==FRONT), In this implementation of Circular Queue, queue can be used for max n-1 elements.

REAR always points the next available slot and FRONT points the slot from where an element can be deleted.
Initially both point to the first cell REAR=FRONT=0,

FULL: (REAR+1)%n== FRONT is correct condition.

PS:  FRONT==REAR how can this be used to check both conditions?
i m talking about front=rear and rear=end for empty case

full condition: (Rear+1)%n==Front

and also can be (Front-1)%n==Rear

empty condition: front==rear

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,517 answers
95,368 users