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

Advertisements

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

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

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

Download Projects

Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs