Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define MAX 5
- void insert(int,int *,int q[],int *r);
- void display(int *,int a[],int *);
- int delete(int *,int *,int q[]);
- int main()
- {
- int choice,item,q[5];
- int front=0,rear=-1,count=0;
- for(;;)
- {
- printf("\n Enter the choice : 1-Insert 2- Display");
- printf(" \n 3-Delete 4-Exit : ");
- scanf("%d",&choice);
- switch (choice)
- {
- case 1 :printf(" \n Enter the number to be added to queue :");
- scanf("%d",&item);
- insert(item,&rear,q,&count);
- break;
- case 2 :display(&front,q,&rear);
- break;
- case 3 :item=deleteq(&front,&count,q);
- if(item==0)
- printf("\n The queue is empty \n");
- else
- printf(" \n The deleted item : %d",item);
- break;
- default:exit(0);
- break;
- }
- }
- }
- void insert(int item,int *rear,int a[5],int *count)
- {
- if(*count==MAX)
- {
- printf(" \n The queue is full \n");
- }
- else
- {
- *rear=(*rear+1)%MAX;
- a[*rear]=item;
- *count=*count+1;
- }
- }
- void display(int *f,int a[5],int *r)
- {
- int i;
- for(i=*f;i<=*r;i++)
- {
- printf("\n %d",a[i]);
- }
- }
- int deleteq(int *f,int *c,int q[5])
- {
- int item;
- if(*c==0)
- {
- return 0;
- }
- else
- {
- item=q[*f];
- *f=(*f+1)%MAX;
- *c=*c-1;
- return item;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement