#include "stdafx.h"
#include<iostream>
using namespace std;
class Queue
{
private:
int first,last,count;
int array[5];
public:
Queue()
{
first=0;
last=-1;
count=0;
}
void set_values(int v)
{
array[++last]=v;
count++;
if(last>=4)
{
last=-1;
}
}
bool IsFull()
{
if(count>=5)
{
return true;
}
else
{
return false;
}
}
int get_values()
{
if(first>=5)
{
first=0;
}
return array[first++];
}
bool IsEmpty()
{
if(count==0)
{
return true;
}
else
{
return false;
}
}
};
int main()
{
Queue s1;
char choice;
int value;
do
{
cout<<"\nDo you want to add or remove data from Queue???(a/r)\n";
cin>>choice;
if(choice=='a')
{
s1.IsFull();
if(s1.IsFull()==true)
{
cout<<"\nQueue is Full!!!\n";
}
else
{
cout<<"\nEnter an Integer:\n";
cin>>value;
s1.set_values(value);
cout<<"\nData added successfully";
}
}
else
{
if(s1.IsEmpty()==true)
{
cout<<"\nQueue is empty!!!\n";
}
else
{
cout<<"\nRemoved data is "<<s1.get_values();
}
}
}while(choice!='e');
return 0;
}
No comments:
Post a Comment