Data Structure
Data Structure
QUEUE:
1: It is one of the types of data structure.
2: It works in FIFO manner i.e. the element inserted first will also be removed first.
3: Queue is also an abstract data type or a linear data structure, in which the first
element is inserted from one end called REAR, and the deletion of existing element
takes place from the other end called as FRONT. This makes queue as FIFO data
structure,
4: The process to add an element into queue is called En-queue and the process of
removal of an element from queue is called De-queue.
5: Figure:
6: Program:
#include<stdio.h>
#include<conio.h>
void main( )
{
int ch,n,rear=0,front=0,i,item,a[100];
clrscr();
printf("\n\n\n\n\n\n enter the size of queue:-");
scanf("%d",&n);
printf("\n\n\n\n *************MENUS***********");
printf("\n1.Insert\n2.Display\n3.Delete\n4.Exit");
do
{
printf("\n\n enter your choice:-");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(rear==n)
{
printf("\n queue is full");
}
else
{
rear++;
printf("\n enter element in queue:-");
scanf("\n%d",&item);
a[rear]=item;
}
break;
case 2:
printf("\n queue contains");
for(i=front+1;i<=rear;i++)
{
printf("\n\n%d",a[i]);
}
break;
case 3:
if(front==rear)
{
printf("\n queue is empty");
}
else
{
front++;
item=a[front];
printf("\n item %d of queue is deleted",item);
}
break;
printf("\n\n\n\n queue contains\n\n");
for(i=front+1;i<=rear;i++)
{
printf("%d",a[i]);
}
break;
case 4:
exit(0);
break;
}}while(ch<=4);
getch();
}
/* output:
enter the size of queue=3
*************MENUS***********
1.Insert
2.Display
3.Delete
4.Exit
enter your choice:- 1
enter element in queue:- 2
enter your choice:- 1
enter element in queue:- 3
enter your choice:- 1
enter element in queue:- 6
enter your choice:- 1
queue is full
enter your choice:- 2
queue contains 2
3
6
enter your choice:-3
item 2 of queue is deleted
enter your choice:-3
item 3 of queue is deleted
enter your choice:-3