QUEUE OPERATION USING ARRAYS


Program


#include <>
#include <>
int n,i,ch,front=-1,rear=-1,s[20],value;
void main()
{
int ch;
clrscr();
printf("\n\t\t QUEUE OPERATION USING ARRAYS");
printf("\n\t\t -------------------------------------------------- ");
printf("\n Enter the queue size:");
scanf("%d",&n);
do
{
printf("\n 1.INSERT\n 2.DELETE\n 3.DISPLAY\n 4.EXIT");
printf("\n Enter Your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
}
}while(ch!=4);
getch();
}
enqueue()
{
if(rear==n-1)
printf("\n Queue is full");
else
{
printf("\n Enter The Data :");
scanf("%d",&value);
rear++;
s[rear]=value;
printf("\n The inserted data is:%d",value);
if(front==-1)
front++;
}
}
dequeue()
{

if(front==-1)
printf("\n Queue is empty");
else
{
value=s[front];
printf("\n The deleted data is:%d",value);
if(front==rear)
{
front=-1;
rear=-1;
}
else
front++;
}
}
display()
{
if(front==-1)
printf("\n Queue is empty");
else
{
printf("\n Queue Values are:");

for(i=front;i < =rear;i++) printf("\n%d",s[i]); } } Output

Enter the queue size: 3

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 1

Enter The Data : 5
The inserted data is: 5

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 1

Enter The Data : 10
The inserted data is: 10

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 3

Queue Values are:
5
10








1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 2



The deleted data is: 5
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 3

Queue Values are:
10

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 4