#include
<stdio.h>
#include
<conio.h>
#define max
10
int
queue[max],rear=-1,front=-1,item;
void
insert()
{
int i,j;
if(rear==max-1)
printf("\nqueue is full");
else
printf("\nenter the element");
scanf("%d",&item);
if(rear==-1 && front==-1)
{
front=0;
rear=0;
}
else
{
rear++;
}
queue[rear]=item;
printf("\nitem inserted is
%d",item);
for(i=0;i<=rear-1;i++)
{
for(j=0;j<=rear-1;j++)
{
if(queue[j]>queue[j+1])
{
int temp=queue[j];
queue[j]=queue[j+1];
queue[j+1]=temp;
}
}
}
}
void delete1()
{
if(front==-1)
printf("\nqueue is empty");
else
{
item=queue[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else
front++;
printf("\nremoved element is
%d",item);
}
}
void display()
{
int i;
if(front==-1)
printf("\nempty");
else
for(i=front;i<=rear;i++)
{
printf("\n%d",queue[i]);
}
}
void main()
{
int ch;
clrscr();
printf("\nMENU
OPTIONS\n1.insert\n2.delete\n3.display\n4.exit");
do
{
printf("\nenter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:insert();
break;
case 2:delete1();
break;
case 3:display();
break;
case 4:exit(0);
default:printf("\ninvalid
choice");
}
}while(ch!=4);
getch();
}
No comments:
Post a Comment