how do i find the number of items in a circular queue?
|front - rear| doesnt always work.
is there one equation to know how many element is in a cir
What do you need to implement a circular queue ?
Answer: you will need front and rear nodes + list of items + count_items.
Of course it is only implemented like this when the queue is finite, when talking about
dynamic allocation it will be different.
Take a look at an example in C Language,
typedef struct
{
TYPE items[MAXSIZE];
TYPE front;
TYPE rear;
int count_items;
} QUEUE;
This will assure you the exact amount of items are currently exist in the queue.
When you want to insert an item to the queue, you will simply increment rear and count_items, and when you want to remove an item from the queue, you will simply decrement rear and count_items.