#include "stdafx.h"
#include<iostream>
using namespace std;
class Stack
{
private:
int array[5];
int top;
public:
Stack()
{
top=-1;
}
bool IsFull()
{
if(top==4)
{
return true;
}
else
{
return false;
}
}
void push_values(int d)
{
array[++top]=d;
cout<<"\nData pushed Successfully\n";
}
bool IsEmpty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
int pop_values()
{
cout<<"\nPopped Data is ";
return array[top--];
}
};
int main()
{
Stack s1;
int value;
char choice;
do
{
cout<<"\nDo you want to add or pop data???press(a/p)\n";
cin>>choice;
if(choice=='a')
{
s1.IsFull();
if(s1.IsFull()==true)
{
cout<<"\nStack is full!!!\n";
cout<<"\nSorry!!!Your request can't be completed\n";
}
else
{
cout<<"Enter an Integer:\n";
cin>>value;
s1.push_values(value);
}
}
else if(choice=='p')
{
s1.IsEmpty();
if(s1.IsEmpty()==true)
{
cout<<"\nStack is empty!!!\n";
}
else
{
cout<<s1.pop_values()<<"\t";
}
}
}
while(choice!='e');
return 0;
}
No comments:
Post a Comment