GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Concepts  >  Data Structures

 Print  |  
Question:  Static Queue Items

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


May 05, 2009 02:00:31 #3
 clickankit4u   Member Since: February 2009    Total Comments: 3 

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

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

     

 

Back To Question