/*Program to empelement Queue operations
compiler- Turbo c++ author- Mangilal Sharma
--------------------------------------------------------*/
#include <process.h>
#include <conio.h>
#include <iostream.h>
#define max 5
class queue
{
private:
int rear,front,choice;
int queue_arr[max];
public:
void insert();
void del();
void display();
queue();
};
void queue::insert()
{
int added_item;
if(rear==(max-1))
{
cout<<"Queue is Overflow\n";
}
else
{
if(front==-1)
front=0;
cout<<"\n Insert the element for adding in Queue: ";
cin>>added_item;
rear=rear+1;
queue_arr[rear]=added_item;
}
}
void queue::del()
{
if(front==-1&&rear==-1)
{
cout<<"Queue is Underflow\n";
return;
}
else
{
cout<<"Element delete from Queue is "<<queue_arr[front];
}
if(rear==front) rear=front=-1;
else if(front==max-1) front=0;
else front=front+1;
}
void queue::display()
{
int i;
if(front==-1)
cout<<"Queue is Empty\n";
else
{
cout<<"Queue is:\n";
for(i=front;i<=rear;i++)
cout<<queue_arr[i];
cout<<"\n";
}
}
queue::queue()
{
rear=-1;
front=-1;
while(1)
{
cout<<"\n\t\t QUEUE\n";
cout<<"\t\t1. To Insert an Element\n";
cout<<"\t\t2. To Delete an Element\n";
cout<<"\t\t3. To Display the Elements\n";
cout<<"\t\t4. To Main page\n";
cout<<"\t\t5. To Exit from Program\n";
cout<<"\n\t\t Enter Your Choice= ";
cin>>choice;
switch(choice)
{
case 1:
insert();break;
case 2:
del();break;
case 3:
display();break;
case 4:
return;
case 5:
exit(1);
default:
cout<<"\n\t\tWrong Choice, Enter Again\n";
}
}
}
/*=========================5Nov.,2010=============================*/
No comments:
Post a Comment
You are welcome, your comment helps me to make this blog more better.