5.
#include<stdio.h>
#include<conio.h>
#include<process.h>
#define MAX_SIZE 4
int Q[MAX_SIZE], f = -1, r = -1;
void main()
{
int ch,x;
void QINSERT(int);
void QDELETE();
void QDISPLAY();
while(1)
{
clrscr();
printf("\n 1.insert \n 2.delete \n 3.display \n 4.exit \n\n enter your choice \n\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n enter the element to be inserted into the queue \n\n");
scanf("%d",&x);
QINSERT(x);
break;
case 2:
QDELETE();
break;
case 3:
QDISPLAY();
break;
case 4:
printf("\n Bye!!! See you later \n");
getch();
exit(0);
default:
printf("\n Invalid choice... try again \n");
} /* end of switch */
printf("\n\n press any key to continue........\n");
getch();
} /* end of while */
} /* end of main */
void QINSERT(int x)
{
if(r>=MAX_SIZE-1)
{
printf("\n queue overflow, insertion not possible \n");
return;
}
r++;
Q[r]=x;
if(f = = -1)
f = 0;
printf("\n element %d has been inserted into the queue \n",x);
}
void QDELETE()
{
int temp;
if(f = = -1)
{
printf("\n queue is empty, deletion not possible \n");
return;
}
temp=Q[f];
if(f = = r)
f = r = -1;
else
f++;
printf("\n deleted element from the queue is %d \n",temp);
}
void QDISPLAY()
{
int i;
if(f = = -1)
{
printf("\n queue is empty \n");
return;
}
printf("\n\n elements of the quere are \n\n");
for(i = f; i <= r; i++)
printf("%d\t",Q[i]);
}
Comments
Post a Comment