#include <iostream>
using namespace std;
class stack{
private:
int size;
int top;
int *arr;
public:
stack(int value){
size=value;
top=-1;
arr = new int[size];
}
bool empty(){
return(top==-1);}
bool full(){
return(top==size-1);}
void push(int v){
if (full()){
cout<<" sorry i cant add : "<< v<<endl;
}
else{
top++;
arr[top]=v;
cout<< v<<" "<<"push succefull"<<endl;
}}
int pop(){
if(empty()){
cout<<" stack is empty"<<endl;
} else{
cout<< " pop succsesful"<<endl;}
return arr[top--];}
int peek(){
return arr[top];}
void display(){
cout<<" your element is "<<endl;
for(int i=top;i>=0;i--){
cout << " valuue is :"<< arr[i]<<" ";
}cout<<endl;
}
};
int main()
{
int si;
cout<< "enter your(stack)size"<<endl;
cin>>si;
cout << " your size now is " << si<<endl;
stack s(si);
cout<<" enter size order for push"<<endl;
int p;
cin>>p;
while (p-->0)
{
int value ;
cout<< "push : value << ";
cin>>value;
s.push(value);
}
s.display();
cout<<"how often do you want to pop : ";
int pop;
cin>>pop;
cout<<endl;
while (pop-->0)
{
cout<<s.pop();
}
cout<<endl;
cout<<" the end value is : "<<s.peek()<<endl;
cout<<"now your element after push and pop is "<<endl;
s.display();
return 0;
}
enter your(stack)size
your size now is 5
enter size order for push
push : value << 1 push succefull
push : value << 2 push succefull
push : value << 3 push succefull
push : value << 4 push succefull
your element is
valuue is :4 valuue is :3 valuue is :2 valuue is :1
how often do you want to pop :
pop succsesful
4 pop succsesful
3
the end value is : 2
now your element after push and pop is
your element is
valuue is :2 valuue is :1