#include<conio.h>
#include<iostream.h>
# define SIZE 150
class Que
{
int front,rear;
int que[SIZE];
public:
Que(){
front=-1;
rear=-1;
}
void ins();
void del();
void disp();
};
void Que::ins()
{
if(rear==(SIZE-1))
{
cout<<"\nQueue is full! OVERFLOW ..";
}
else
{
int item;
cout<<"\nEnter element to be inserted : ";
cin>>item;
if(front==(-1) && rear==(-1))
{rear=0;front=0;}
else
rear=rear+1;
que[rear]=item;
cout<<"\nSuccess..\n";
}
}
void Que::del()
{
if(front != (-1))
{
cout<<"\n"<<que[front]<<" is deleted ..\n";
if(front==rear)
front=rear=(-1);
else
front=front+1;
}
}
void Que:: disp()
{
int i;
if(front==(-1))
{cout<<"\nQueue is empty. \n";}
else
{
cout<<"\nThe queue is :\n";
for(i=front;i<=rear;i++)
cout<<que[i]<<" ";
cout<<"\n";
}
}
void main()
{
clrscr();
int element,choice;
Que q;
clrscr();
while(choice!= 4)
{
cout<<"\nMENU \n1: INSERT.\n2: REMOVE.";
cout<<"\n3: VIEW\n4: QUIT";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1: q.ins();q.disp();break;
case 2: q.del();q.disp();break;
case 3: q.disp();break;
case 4: choice=4;cout<<"Press any key..";break;
default:cout<<"Please re-enter your choice.";break;
}
}
getch();
}
#include<iostream.h>
# define SIZE 150
class Que
{
int front,rear;
int que[SIZE];
public:
Que(){
front=-1;
rear=-1;
}
void ins();
void del();
void disp();
};
void Que::ins()
{
if(rear==(SIZE-1))
{
cout<<"\nQueue is full! OVERFLOW ..";
}
else
{
int item;
cout<<"\nEnter element to be inserted : ";
cin>>item;
if(front==(-1) && rear==(-1))
{rear=0;front=0;}
else
rear=rear+1;
que[rear]=item;
cout<<"\nSuccess..\n";
}
}
void Que::del()
{
if(front != (-1))
{
cout<<"\n"<<que[front]<<" is deleted ..\n";
if(front==rear)
front=rear=(-1);
else
front=front+1;
}
}
void Que:: disp()
{
int i;
if(front==(-1))
{cout<<"\nQueue is empty. \n";}
else
{
cout<<"\nThe queue is :\n";
for(i=front;i<=rear;i++)
cout<<que[i]<<" ";
cout<<"\n";
}
}
void main()
{
clrscr();
int element,choice;
Que q;
clrscr();
while(choice!= 4)
{
cout<<"\nMENU \n1: INSERT.\n2: REMOVE.";
cout<<"\n3: VIEW\n4: QUIT";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1: q.ins();q.disp();break;
case 2: q.del();q.disp();break;
case 3: q.disp();break;
case 4: choice=4;cout<<"Press any key..";break;
default:cout<<"Please re-enter your choice.";break;
}
}
getch();
}