Monday 12 December 2011

WAP to implement the concept of queue.


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
void insert();
void del();
void dis();
void exo();
void show();
int queue[MAX],i,ch,ft=-1,rr=-1;
void main()
{

clrscr();
show();
getch();
}

void insert()
{
if(ft==MAX-1)
{
printf("\nQueue is full ");
}
else
{       rr=0;
ft++;
printf("\nEnter the element in queue ");
scanf("%d",&queue[ft]);
}
}
void del()
{
if(rr==-1)
{
printf("\nQueue if empty ");
}
else
{

printf("\nThe deleted element is %d",queue[rr]);
}
ft--;
rr++;

}
void dis()
{
if(rr==-1)
{
printf("\nQueue doesn't have any element in it ");
}
else
{
for(i=rr;i<=ft;i++)
{
printf("\n%d",queue[i]);
}
}
}
void exo()
{
exit (0);
}
void show()
{
do
{
printf("\nEnter your choice");
printf("\n1. Insert");
printf("\n2. Delete");
printf("\n3. Display");
printf("\n4. Exit ");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
break;
case 2: del();
break;
case 3: dis();
break;
case 4: exo();
break;
default: printf("\nWrong Choice ");
break;
}
}while(ch!=4);
}

No comments:

Post a Comment