/*Program to impelement Dequeue operations
compiler- Turbo c++ author- Mangilal Sharma
--------------------------------------------------------*/
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define max 5
class dqueue
{
private:
int queue_arr[max],rear,front,choice;
public:
void insertL();
void insertR();
void delL();
void delR();
void display();
void menu(int);
dqueue();
};
void dqueue::insertL()
{
int added_item;
if(front==0)
{
cout<<"Queue is Overflow\n";
return;
}
else
{
cout<<"\n Insert the element for adding in DeQueue: ";
cin>>added_item;
}
front=front-1;
queue_arr[front]=added_item;
}
void dqueue::insertR()
{
int added_item;
if(rear==(max-1))
{
cout<<"Queue is Overflow\n";
return;
}
else
{
cout<<"\n Insert the element for adding in DeQueue: ";
cin>>added_item;
}
if(front==-1)
front=0;
rear=rear+1;
queue_arr[rear]=added_item;
}
void dqueue::delR()
{
if(front==rear+1)
{
cout<<"DeQueue is Underflow\n";
return;
}
else
cout<<"Element delete from DeQueue is "<<queue_arr[rear];
rear=rear-1;
}
void dqueue::delL()
{
if(front==rear+1)
{
cout<<"DeQueue is Underflow\n";
return;
}
else
cout<<"Element delete from DeQueue is "<<queue_arr[front];
front=front+1;
}
void dqueue::display()
{
int i;
if(front<=rear)
{
cout<<"DeQueue is:\n";
for(i=front;i<=rear;i++)
cout<<queue_arr[i];
cout<<"\n";
}
else
{
cout<<"Dequeue is empty";
}
}
void dqueue::menu(int n)
{
while(1)
{
cout<<"\n\t\t\t Menu";
cout<<"\n\n\t\t1. To Insert an Element\n";
if(n==2)
cout<<"\t\t2. To Insert an Element at left\n";
if(n==1)
cout<<"\t\t2. To Delete an Element from right\n";
cout<<"\t\t3. To Delete an Element\n";
cout<<"\t\t4. To Display the Elements of DeQueue\n";
cout<<"\t\t5. To Exit from Programme\n";
cout<<"\n\t\t Enter Your Choice= ";
cin>>choice;
switch(choice)
{
case 1:insertR();break;
case 2:if(n==1)delR();
if(n==2)insertL();break;
case 3:delL();break;
case 4:display();break;
case 5:exit(1);
default: cout<<"\n\t\tWrong Choice, Enter Again\n";
}
}
}
dqueue::dqueue()
{
rear=-1,front=-1;
cout<<"\n\t\t\t DQUEUE\n";
cout<<"\t\t1. input restriced dequeue\n";
cout<<"\t\t2. output restriced dequeue\n";
cout<<"\t\t3. To main menu\n";
cout<<"\t\t4. To Exit from Programme\n";
cout<<"\n\t\t Enter Your Choice= ";
cin>>choice;
switch(choice)
{
case 1:
menu(1);break;
case 2:
menu(2);break;
case 3:
return;
case 4:
exit(1);
default:
cout<<"\n\t\tWrong Choice, Enter Again\n";
}
}
/*=========================6Nov.,2010=============================*/
nice article for beginners.thank you.
ReplyDeletec tutorial
java tutorial