Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 10
- struct queue
- {
- int rear;
- int front;
- int q[MAX];
- };
- void insert(struct queue *s,int item);
- void del(struct queue *s);
- void display(struct queue *s);
- int main()
- { int ch,item;
- struct queue q;
- q.rear=0;
- q.front=0;
- while(1)
- {
- printf("Enter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:printf("Enter the element to be inserted");
- scanf("%d",&item);
- insert(&q,item);
- break;
- case 2:del(&q);
- break;
- case 3:display(&q);
- break;
- case 4: exit(0);
- }
- }
- return 0;
- }
- void insert(struct queue *s,int item)
- {
- if(s->rear==MAX-1)
- {
- printf("Queue is full");
- return;
- }
- s->q[s->rear]=item;
- s->rear++;
- return;
- }
- void del(struct queue *s)
- {
- if(s->front==s->rear)
- {
- printf("Queue is empty");
- return;
- }
- printf("Deleted element is %d",s->q[s->front]);
- s->front++;
- }
- void display(struct queue *s)
- {
- for(int i=s->front;i<s->rear;i++)
- printf("%d",s->q[i]);
- return;
- }
Add Comment
Please, Sign In to add comment