Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program for circular queue
- #include<stdio.h>
- #include<conio.h>
- int front,rear;
- void insertion(int a[],int size)
- {
- int elem;
- if((rear+1)%size==front)
- {
- printf("\n Overflow.\n");
- getch();
- return;
- }
- printf("\n Enter the element for queue : ");
- scanf("%d",&elem);
- rear=(rear+1)%size;
- a[rear]=elem;
- if(front==-1)
- front=0;
- return;
- }
- void deletion(int a[],int size)
- {
- if(front==-1)
- {
- printf("\n Underflow.\n");
- getch();
- return;
- }
- if(front==rear)
- {
- printf("\n The element to be deleted is %d",a[front]);
- getch();
- front=rear=-1;
- return;
- }
- printf("\n The element to be deleted is %d",a[front]);
- front=(front+1)%size;
- getch();
- return;
- }
- void print(int a[],int size)
- {
- int i;
- if(rear==-1)
- {
- printf("\n No elements in queue.\n");
- getch();
- return;
- }
- i=front;
- while(i!=rear)
- {
- printf(" %d",a[i]);
- i=(i+1)%size;
- }
- printf(" %d",a[i]);
- getch();
- return;
- }
- void main()
- {
- int a[15],size,ch;
- clrscr();
- printf("\n Enter the size of the queue : ");
- scanf("%d",&size);
- front=rear=-1;
- while(ch!=4)
- {
- printf("\n\n\t MENU");
- printf("\n\t1.INSERTION");
- printf("\n\t2.DELETION");
- printf("\n\t3.DISPLAY");
- printf("\n\t4.EXIT");
- printf("\n Enter your choice : ");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:insertion(a,size); break;
- case 2:deletion(a,size); break;
- case 3:print(a,size); break;
- case 4:exit(0);
- default:printf("\n Sorry wrong input.");
- }
- clrscr();
- }
- getch();
- }
Add Comment
Please, Sign In to add comment