Static Queue Items

Write an algorithm to calculate the number of items in a static queue?

Questions by nurulyusliana

Showing Answers 1 - 15 of 15 Answers

sharmilag

  • Feb 8th, 2009
 

[F=front, R=rear, P= pointer, q[] is the array variable]
Algorithm:
     if F != R
       F = P
       count = 0
       while(P <= R)
       {
          count = count + 1;
          P = P+1;
        }
 //Display count which shows number of elements in queue.

Queue: array in which you insert at front and remove from rare.

Static Queue: queue which is of fix size and can not variate in size at runtime.

Optimized way to count the elements present.


F -> front
R -> rare
No -> no of elements present
Max_size -> max size of queue.

********************************************************************

if(F > R)
No = F - R;
else if( R > F)
No = ((Max_size - R) + F)
else
No = 0

********************************************************************

  Was this answer useful?  Yes

[F=front, R=rear, P= pointer, q[] is the array variable]
Algorithm:
     if F != R
       P= F
       count = 0
       while(P <= R)
       {
          count = count + 1;
          P = P+1;
        }
 //Display count which shows number of element

  Was this answer useful?  Yes

[F front R rear P pointer q[] is the array variable] 
Algorithm: 
if (F != R)
P= F
count =0 
while(P <= R) 
{
count count + 1;
P P+1; 
}
//Display count which shows number of element

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions