Advertisement
yuawn

vector_stack

Oct 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define MAX 500
  5.  
  6. struct Stack{
  7.     vector<int> p;
  8.     bool isempty(){ return !p.size(); };
  9.     bool isfull(){ return p.size() == MAX; };
  10.     void push( int n ) {
  11.         if( p.size() == MAX - 1 ) puts("Full!");
  12.         else p.pb(n);
  13.     };
  14.     int pop(){
  15.         if( !p.size() ) puts("Empty");
  16.         else {
  17.             int top = p[p.size() - 1];
  18.             p.pop_back();
  19.             return top;
  20.         }
  21.     }
  22. };
  23.  
  24. int main(){
  25.     Stack stk;
  26.     stk.push(1);
  27.     stk.push(2);
  28.     stk.push(3);
  29.     cout << stk.pop() <<endl;
  30.     cout << stk.pop() <<endl;
  31.     cout << stk.isempty() << endl;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement