How we traverse the Queue ?
When we think about that how we display or traverse the queue then two idea come in mind that
- traverse from front to rear
or
- traverse from rear to front
Which one is correct ?
'front to rear traverse' is the correct one because we traverse the element which come first in queue
Following is the which are used to display the queue from to rear:
void display()
{
int i;
if (front==-1)
printf("Queue is empty \n");
else
{
printf("Queue is : \n");
for (i =front; i< = rear; i++)
printf("%d ", queue[i]);
}
}