Queue Program in C++

Advertisements

Prev Tutorial Next Tutorial

Queue Program in C++

Queue Program in C++

	
#include<iostream.h>
#include<conio.h>

void insert();
void del();
void display();

struct circ
{
int cqueue[5];
};

struct  circ cque;
int rear=0,front=-1;

void main()
{
while(1)
{
int num;
 clrscr();
cout<<"1.Insertion\n2.Deletion\n3.Display\n0.Exit\n";
cout<<"\n\nSelect Option : ";
cin>>num;
switch(num)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 0:
exit(0);
break;
default:
cout<<"\n\n Invalid Option ";
}
getch();
}
}

void insert()
{
int item;
cout<<"Element : ";
cin>>item;
if(front==(rear+1)%3)
{
cout<<"Queue is Full";
return;
}
if(front==-1)
{
rear=front=0;
}
else
{
rear=(rear+1)%3;
}
cque.cqueue[rear]=item;
cout<<"Successfully Insert";
}

void del()
{
int num;
if(front==-1)
{
cout<<"Queue Empty";
return;
}
else
{
num=cque.cqueue[front];
cout<<"Deleted item : "<<num;
}
if(front==rear)
{
front=-1;
}
else
front=(front+1)%3;
}

void display()
{
int i;
if(front==-1)
{
cout<<"Queue Empty";
return;
}
else
{
cout<<"\n\nItems : ";
for(i=front;i<=rear;i++)
{
cout<<"   "<<cque.cqueue[i];
}
}
}
queue output
Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements