int r=-1,f=0;
void push(int a[],int);
void pop(int a[]);
void traverse(int a[]);
int main()
{
int p=1,a[20],n=4,i ,b;
while(p)
{
printf("\n Enter 1 to PUSH the queue");
printf("\n Enter 2 to POP the queue");
printf("\n Enter 3 to display the ");
printf("\n Enter 4 to exit loop");
scanf("%d",&b);
switch(b)
{
case 1:
push(a,n);
break;
case 2:
pop(a);
break;
case 3 :
traverse(a);
break;
case 4 :
p=0;
break;
}
}
return 0;
}
void push(int a[],int n)
{
int data;
if(r==n-1)
{
printf("\n The queue is over flow");
}
else
{
r=r+1;
printf("Enter the data");
scanf("%d",&data);
a[r]=data;
}
}
void pop(int a[])
{
if ( f>r)
{
printf("\n The queue is underflow");
}
else if(f==r)
{
f=0;
r=-1;
}
else
{
f=f+1;
}
}
void traverse(int a[])
{
int i;
printf("\n The elements of the queue ..\n");
for(i=f;i<=r;i++)
{
printf("\n Arr[%d]=[%d]",i,a[i]);
}
}
No comments:
Post a Comment