Docsity

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

Toggle sidebar
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