C++ Queue Implementation, Exercises of Data Structures and Algorithms

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

2011/2012

Uploaded on 07/30/2012

dhanvantari
dhanvantari 🇮🇳

2

(2)

45 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#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();
}
docsity.com

Partial preview of the text

Download C++ Queue Implementation and more Exercises Data Structures and Algorithms in PDF only on Docsity!

#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(); }

docsity.com