daily pastebin goal
18%
SHARE
TWEET

Lab 7 - Stack

RaresDumitrica Jan 17th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define MAX 9999
  6.  
  7. class Stack {
  8.     int top;
  9.  
  10. public:
  11.     int a[MAX]; // Marimea maxima a stivei
  12.  
  13.     Stack()
  14.     {
  15.         top = -1;
  16.     }
  17.     bool push(int x);
  18.     int pop();
  19.     bool isEmpty();
  20. };
  21.  
  22. bool Stack::push(int x)
  23. {
  24.     if (top >= (MAX - 1))
  25.     {
  26.         cout << " a";
  27.         return 0;
  28.     }
  29.     else
  30.     {
  31.         a[++top] = x;
  32.         cout << x << " pushed into stack\n";
  33.         return 1;
  34.     }
  35. }
  36.  
  37. int Stack::pop()
  38. {
  39.     if (top < 0)
  40.     {
  41.         cout << ";
  42.        return 0;
  43.    }
  44.    else
  45.    {
  46.        int x = a[top--];
  47.        return x;
  48.    }
  49. }
  50.  
  51. bool Stack::isEmpty()
  52. {
  53.    return (top < 0);
  54. }
  55.  
  56. int main()
  57. {
  58.    struct Stack s;
  59.    s.push(10);
  60.    s.push(20);
  61.    s.push(30);
  62.    cout << s.pop() << " Popped from stack\n";
  63.  
  64.    return 0;
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top