// Do not forget to take a look at that both stack-queue class implementation ! label is stackqueue
#include<iostream>
using namespace std;
class Queue
{
int rear,front,Q[5];
public:
void set()
{
rear=front=-1;
}
int full()
{
if(rear>=4)
return 1;
else
return 0;
}
int empty()
{
if(front==-1 || front>rear )
return 1;
else
return 0;
}
void insert(int i)
{
if(front==-1)
{
front++;
}
Q[++rear]=i;
}
void display()
{
int i;
for(i=front;i<=rear;i++)
{
cout<<" "<<Q[i];
}
}
void del()
{
front++;
}
};
int main()
{
Queue q;
int i,ch;
q.set();
do{
cout<<"\n1.insert\n2.delete\n3.display\n4.0 for exit";
cin>>ch;
switch(ch)
{
case 1:if(q.full()){
cout<<"\nQueue is full";
}
else{
cout<<"\nEnter element:";
cin>>i;
q.insert(i);
}
break;
case 2:if(q.empty())
{
cout<<"\nQueue is empty";
}else
{
q.del();
}
break;
case 3:if(q.empty())
{
cout<<"\nQueue is empty";
}else
{
q.display();
}
break;
default : cout<<"\nProper choice plz";
}
}while(ch!=0);
return 0;
}
#include<iostream>
using namespace std;
class Queue
{
int rear,front,Q[5];
public:
void set()
{
rear=front=-1;
}
int full()
{
if(rear>=4)
return 1;
else
return 0;
}
int empty()
{
if(front==-1 || front>rear )
return 1;
else
return 0;
}
void insert(int i)
{
if(front==-1)
{
front++;
}
Q[++rear]=i;
}
void display()
{
int i;
for(i=front;i<=rear;i++)
{
cout<<" "<<Q[i];
}
}
void del()
{
front++;
}
};
int main()
{
Queue q;
int i,ch;
q.set();
do{
cout<<"\n1.insert\n2.delete\n3.display\n4.0 for exit";
cin>>ch;
switch(ch)
{
case 1:if(q.full()){
cout<<"\nQueue is full";
}
else{
cout<<"\nEnter element:";
cin>>i;
q.insert(i);
}
break;
case 2:if(q.empty())
{
cout<<"\nQueue is empty";
}else
{
q.del();
}
break;
case 3:if(q.empty())
{
cout<<"\nQueue is empty";
}else
{
q.display();
}
break;
default : cout<<"\nProper choice plz";
}
}while(ch!=0);
return 0;
}
No comments:
Post a Comment