Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define MAX 50
- struct QUEUE
- {
- int data[MAX];
- int front, rear;
- }q;
- void print()
- {
- int i;
- printf("\nthe queue is \t front->");
- for(i=q.front;i<=q.rear;i++)
- printf("%d->",q.data[i]);
- printf("Rear");
- }
- int main()
- {
- int ch,x;
- q.front=0;
- q.rear=-1;
- do
- {
- printf("\n\n1.insert\n2.delete\n3.display\n4.exit\n enter ch: ");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:
- if(q.rear==MAX)
- {
- printf("\nQ full");
- }
- else
- {
- printf("Enter the element to add");
- scanf("%d",&x);
- q.rear++;
- q.data[q.rear]=x;
- }
- print();
- break;
- case 2:
- if(q.front> q.rear)
- {
- printf("q empty");
- }
- else
- {
- x=q.front;
- q.front++;
- printf("\n%d deleted",x);
- }
- print();
- break;
- case 3:
- print();
- break;
- case 4:
- break;
- }
- }while(ch!=4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment