# include<iostream.h>
# include<conio.h>
# include<process.h>
# define SIZE 5
class queue
{
int a[SIZE];
int front;
int rear;
public:
queue();
~queue();
void insert(int i);
void remove();
void display();
int isempty();
int isfull();
};
queue::queue()
{
front=0;
rear=0;
}
queue::~queue()
{
delete a;
}
void queue::insert(int i)
{
a[rear++] = i;
}
void queue::remove()
{
cout<<"\n\nDELETED ELEMENT IS : "<<a[front];
for(int i=0;i<rear;i++)
a[i]=a[i+1];
rear--;
}
void queue::display()
{
cout<<"\n";
for(int i=front;i<rear;i++)
cout<<"\t"<<a[i];
}
int queue::isempty()
{
if(front == rear)
return 1;
else
return 0;
}
int queue::isfull()
{
if(rear >= SIZE)
return 1;
else
return 0;
}
void main()
{
queue q;
int ch;
clrscr();
while(1)
{
cout<<"\n\nMAIN MENU";
cout<<"\n1.INSERTION";
cout<<"\n2.DELETION";
cout<<"\n3.EXIT";
cout<<"\n\nENTER YOUR CHOICE : ";
cin>>ch;
switch(ch)
{
case 1:
int num;
if(q.isfull())
{
cout<<"\nQUEUE IS FULL\n";
}
else
{
cout<<"\n\nENTER THE QUEUE ELEMENT : ";
cin>>num;
q.insert(num);
}
q.display();
break;
case 2:
if(q.isempty())
{
cout<<"\nQUEUE IS EMPTY\n ";
}
else
{
q.remove();
}
q.display();
break;
case 3:
cout<<"\n GOOD BYE!!!!!";
exit(0);
default:
cout<<"Invalid choice...";
}
}
getch();
}
No comments:
Post a Comment