// Queue
#include<stdio.h>
#include<conio.h>
#define MAX 5
int ch,front=-1,rear=-1,queue[MAX],item;
void main()
{
clrscr();
while(1)
{
printf("*** Menu ***\n 1. Insert\n 2. Delete\n 3. Display\n 4. Exit\n");
printf("Enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
break;
case 2: del();
break;
case 3: display();
break;
case 4: exit();
default:
printf("You are out of choice!");
}
}
}
int insert()
{
int added_item;
if(rear==MAX-1)
printf("Queue overflow i.e. full!");
else
{
if(front==-1) //If queue is initially empty
front=0;
printf("Enter the item to adding in the queue");
scanf("%d",&added_item);
rear++;
queue[rear]=added_item;
}
return 0;
}
int del()
{
if(front==-1||front>rear)
{
printf("Queue is underflow i.e. empty\n");
}
else
{
printf("The deleted item from queue is %d\n",queue[front]);
front++;
}
return 0;
}
int display()
{
int i;
if(front==-1)
printf("Queue is underflow!");
else
{
printf("Queue display\n");
for(i=front;i<=rear;i++)
{
printf("%d",queue[i]);
}
printf("\n");
}
return 0;
}
Tags
MCA