GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Concepts  >  Data Structures
Go To First  |  Previous Question  |  Next Question 
 Data Structures  |  Question 199 of 202    Print  
Static Queue Items
Write an algorithm to calculate the number of items in a static queue?


  
Total Answers and Comments: 4 Last Update: September 23, 2009     Asked by: nurulyusliana 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sharmilag
 
[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.


Above answer was rated as good by the following members:
Rizwan Saeed Shaikh
February 08, 2009 07:25:35   #1  
sharmilag Member Since: February 2009   Contribution: 1    

RE: Static Queue Items
[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.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
April 13, 2009 12:07:42   #2  
piyushbeli Member Since: September 2007   Contribution: 4    

RE: Static Queue Items
F Front
R Rear
q array of queue
p pointer to array

if(F Null)
return 0;
count 1
while(p! R)
{
count++;
p p+1;
}

 
Is this answer useful? Yes | No
May 31, 2009 02:00:31   #3  
clickankit4u Member Since: February 2009   Contribution: 6    

RE: Static Queue Items

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

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


 
Is this answer useful? Yes | No
September 23, 2009 00:30:13   #4  
boyanamadhavilatha Member Since: September 2009   Contribution: 1    

RE: Static Queue Items
[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

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape