using namespace std;
class queue
{
int front,rear;
int item[3];
public:
void insert(int);
int remove();
void display();
void setvalues()
{
front=-1;
rear=0;
}
};
void queue::insert(int m)
{
item[rear++]=m;
}
int queue::remove()
{
int x;
if(front==-1)
cout<<"empty";
x=item[++front];
return(x);
}
void queue::display()
{
int i=front+1;
for loop upto rear then print the items according to item[i]
}
int main()
{
queue s;
int item,ch;
s.setvalues();
while(1)
{
cout<<"optoins:-\npress 1 for inserting the elements\npress 2 for removing the element\npress 3 for display the result\npress any key for exit\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"enter your item";
cin>>item;
s.insert(item);
break;
case 2:
item=s.remove();
print the item.
break;
case 3:
s.display();
break;
default:
exit(1);
}
}
}
0 comments:
Post a Comment