#include<stdio.h>
#include<conio.h>
int q[5],r=-1,f=-1;
void insert(int x)
{
if(r==4)
{
printf("Queue is full");
return;
}
r++;
q[r]=x;
if(f==-1)
f=0;
}
int del()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=q[f];
if(f==r)
{
f=-1;
r=-1;
}
else
{
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("No elements in Queue");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",q[i]);
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insert(x);
break;
case 2:
x=del();
printf("\n Deleted value is %d",x);
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}
}while(n!=4);
getch();
}
#include<conio.h>
int q[5],r=-1,f=-1;
void insert(int x)
{
if(r==4)
{
printf("Queue is full");
return;
}
r++;
q[r]=x;
if(f==-1)
f=0;
}
int del()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=q[f];
if(f==r)
{
f=-1;
r=-1;
}
else
{
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("No elements in Queue");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",q[i]);
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insert(x);
break;
case 2:
x=del();
printf("\n Deleted value is %d",x);
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}
}while(n!=4);
getch();
}
No comments:
Post a Comment