Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<conio.h>
- #include<stdio.h>
- #define max 100
- typedef struct
- {
- int q[max];
- int f,r;
- }queue;
- int isempty(queue *t)
- {
- if(t->f==t->r+1)
- return 1;
- else return 0;
- }
- void insert(queue *t,int ele)
- {
- if(t->r==max-1)
- {
- printf("\nQUEUE OVERFLOW\n");
- return ;
- }
- t->r++;
- t->q[t->r] = ele;
- return;
- }
- void delete1(queue *t)
- {
- int z;
- if(isempty(t)==1)
- {
- printf("\nQUEUE UNDERFLOW\n");
- return ;
- }
- z = t->q[t->f];
- t->f++;
- printf("Deleted element is %d",z);
- return;
- }
- void queuefront(queue *t)
- {
- int z;
- if(isempty(t)==1)
- {
- printf("\nQUEUE UNDERFLOW");
- return;
- }
- z = t->q[t->f];
- printf("QUEUEFRONT is %d",z);
- return;
- }
- void display(queue *t)
- {
- int i;
- if(isempty(t)==1)
- {
- printf("\nQUEUE UNDERFLOW");
- return;
- }
- printf("\nELEMENT OF QUEUE ARE SHOWN BELOW\n");
- for(i=t->f;i<=t->r;i++)
- {
- printf("%d\t",t->q[i]);
- }
- return ;
- }
- int main()
- {
- int ch,ele;
- queue x;
- x.f = 0;
- x.r = -1;
- printf("IMPLEMENTATION OF SIMPLE QUEUE USING ARRAY");
- while(1)
- {
- printf("\nENTER CHOICE \n1.INSERT 2.DELETE 3.QUEUEFRONT 4.DISPLAY 5.EXIT\n");
- scanf_s("%d",&ch);
- if(ch==5)
- {
- break;
- }
- switch(ch)
- {
- case 1:printf("\nEnter element to insert\n");
- scanf_s("%d",&ele);
- insert(&x,ele);
- break;
- case 2:delete1(&x);
- break;
- case 3:queuefront(&x);
- break;
- case 4:display(&x);
- break;
- default:printf("\nINVALID INPUT");
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement