data structure: Queue

A queue is a container of objects (a linear collection) that are inserted and removed according to the first-in first-out (FIFO) principle. An excellent example of a queue is a line of students in the food court of the canteen. New additions to a line made to the back of the queue, while removal (or serving) happens in the front. In the queue only two operations are allowed enqueue and dequeue. Enqueue means to insert an item into the back of the queue, dequeue means removing the front item.

In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once a new element is added, all elements that were added before have to be removed before the new element can be removed. Often a peek or front operation is also entered, returning the value of the front element without dequeuing it. A queue is an example of a linear data structure, or more abstractly a sequential collection.

implementation of queue in c::

#include<stdio.h>#include<conio.h>#include<process.h>

void main(){int a[5],i,f=-1,r=-1,c;clrscr();do{printf(“nEnter the operation you want to perform:”);printf(“1:insert.”);printf(“2:delete.”);printf(“3:display.”);printf(“4:exit.”);scanf(“%d”,&c);