Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class stack{
- int size,last;
- int*arr;
- public:
- stack(int n){
- size=n;
- last=-1;
- arr=new int[n];
- }
- void push(int x){
- if(last==size-1)cout<<"FULL\n";
- else{
- last++;
- arr[last]=x;
- cout<<"Push: "<<x<<endl;
- }
- }
- void pop(){
- if(last==-1)cout<<"Empty\n";
- else{
- int x=arr[last];
- last--;
- cout<<"Pop: "<<x<<endl;
- }
- }
- void middle(){
- if(last==-1)cout<<"empty\n";
- else{
- cout<<"Middle: "<<arr[last/2]<<endl;
- }
- }
- };
- int main()
- {
- stack st(3);
- st.push(1);
- st.middle();
- st.push(2);
- st.push(3);
- st.middle();
- st.push(4);
- st.middle();
- st.push(5);
- st.pop();
- st.pop();
- st.push(6);
- st.middle();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment