
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 in c++ using an array. The program takes user input for the number of pages and adds it to the queue, checks for queue overflow, and displays the queue elements. This can be useful for students and developers learning data structures and c++ programming.
Typology: Exercises
1 / 1
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,i=0,input; clrscr(); cout<<"Enter your choice\n\t\tTo enter press: 1\n\t\tTo exit press:2\n"; cin>>input; while (input==1) { cout<<"Enter the number of pages\n"; cin>>choice; if(front==-1||rear==-1) { front=0; rear=0; queue[rear]=choice; } if(rear>(max-1)) { cout<<"The queue is full\n"; } else { rear=0; while (choice>queue[rear]) { rear++; for(int j=max;j>rear;j--) { queue[j]=queue[j-1]; } } queue[rear]=choice; } cout<<"The Queue is:\n"; for(int k=0;k<=10;k++) { cout<<queue[k]<<" "; } cout<<"\nEnter Choice\n"; cin>>input; } getch(); }