

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The implementation of a queue data structure using c++. The user can perform dequeue, enqueue, display, and exit operations on the queue. The program checks for queue underflow and overflow conditions before performing the respective operations.
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


#include<conio.h> #include<iostream.h> int rear=-1,front=-1,queue[10],max=10; void main (void) { int choice,input; clrscr(); cout<<"Enter one of the following options\n\n\t--> To Dequeue enter: 1\n\t--> To enqueue enter: 2\n\t--> To display enter: 3\n\t--> To exit enter: 4\n"; cin>>choice; while (choice!=4) { switch (choice) { case 1: if(front==-1 || rear==-1) { cout<<"The queue is empty\n"; } else { for (int i=front;i<rear;i++) { queue[i]=queue[i+1]; } rear--; } break; case 2: if (rear==(max-1)) { cout<<"The queue is full\n"; } else { if (front==-1) { front=0; } cout<<"Enter the number you want to enqueue: "; cin>>input; rear++; queue[rear]=input; } break; case 3: cout<<"\n"; for(int i=0;i<=rear;i++) { cout<<queue[i]<<" "; }cout<<"\n"; break; default:
cout<<"You entered the wrong choice please enter again\n"; } cout<<"\nEnter choice : "; cin>>choice; } getch(); }