Pages

E-mail us at prgms4starters@gmail.com for any queries or to share your programs. Please mention the program definition in the subject line.

In case you need help in finishing a program, do mention "incomplete pgm" in the subject line. Our team of experts will do their best to help you.

Click the link to follow this page for updates and reminders: FOLLOW THIS SITE

You can also visit our Facebook page by clicking HERE

**don't forget to participate in the polls at the bottom of the page

Friday, November 5, 2010

C++ program for the application of QUEUE

#include<iostream>
#include<conio.h>
#include<process.h>
using namespace std;
int f,r,q[50],n;
class queue
{
public:

void insert();
void deletion();
void front();
void rear();
void display();
void clearq();
void qsize();
};

void queue::insert()
{ int item;
if(r==(n-1))
{
cout<<"\n queue overflow";
}
else
{
if(r==-1 &&f==-1)
{
f=0;
r=0;
}
else
{
r++;
}
cout<<"\n enter the item to enter ";
cin>>item;
q[r]=item;
}

}
void queue::deletion()
{
int item;

if(f>r||(f==-1&&r==-1))
{
cout<<"\n underflow";
f=-1;
r=-1;
}
else
{
item=q[f];
f=f+1;
cout<<"\n deleted item ="<<item;
}
}
void queue::front()
{
if(f>r||(f==-1&&r==-1))
cout<<"\n underflow";
else
cout<<"\n queue front="<<q[f];
}
void queue::rear()
{
if(r>=n)
cout<<"\n overflow";
else
cout<<"\n queue rear="<<q[r] ;
}

void queue::display()
{
int i;
if(f==-1)
cout<<"\n no element element has been inserted";
else
{
for(i=f;i<=r;i++)

cout<<"|"<<q[i]<<"|";

}
}
void queue::clearq()
{
if(f>r)
cout<<"\n no element inserted";
else
{
q[r]='\0';
}
f=-1;
r=-1;
}
void queue::qsize()
{ int size;
if(f==-1&&r==-1)
cout<<"\n the queue is empty";
else
{
size=(r-f)+1;
cout<<"\n size of queue is="<<size;
}
}
void main()
{ f=-1;
r=-1;
int w=1,ch;
queue q1;
system("cls");
cout<<"\n ENTER THE MAXIMUM SIZE OF THE QUEUE";
cin>>n;
while(w==1)
{
system("cls");
cout<<"\n WELCOME TO THE MENU ";
cout<<"\n ====================================================";
cout<<"\n 1.To insert an element into the queue \n 2.To delete an element from the queue \n 3.To display front of the queue \n 4.To dispaly the rear of the queue \n 5.To display the elements in the queue \n 6.TO clear the queue \n 7.To show the size of the queue \n 8.exit";
cout<<"\n ===================================================";
cout<<"\n PLEASE ENTER ANY OF THE ABOVE CHOICE ";
cin>>ch;
switch(ch)
{
case 1:q1.insert();
break;
case 2:q1.deletion();
break;
case 3:q1.front();
break;
case 4:q1.rear();
break;
case 5:q1.display();
break;
case 6:q1.clearq();
cout<<"\n the queue has been cleared";
break;
case 7:q1.qsize();
break;
case 8:exit(0);
break;
default: cout<<"\n invalid entry";
}
cout<<"\n press (1) to continue or any other digit to exit";
cin>>w;
}
}

No comments:

Post a Comment

We have noticed that 20% of our visitors are still using internet explorer. For a better and faster surfing experience we recommend that you switch to either Google Chrome or Mozilla Firefox. We cannot provide you the downloads but here are the links to sites where you can download them from

Google Chrome - click here to go to site

Mozilla Firefox - click here to go to site

Where are you from

Do you think this site was helpful

Should we put up more C or C++ programs