The Gateway to Computer Science Excellence
0 votes
174 views

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

       (or)

      (FRONT+1)%n==REAR

       (or)

     FRONT==REAR

      

 Empty:   FRONT==REAR

       (or)

              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 Veteran (117k points) | 174 views
0
i think for full : (rear+1)mod n ==front       for empty: both as you mentioned.
+1
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?
0
i m talking about front=rear and rear=end for empty case
0

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

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

0
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
50,648 questions
56,430 answers
195,213 comments
99,930 users