Guest User

Untitled

a guest
Oct 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class stog {
  7. public:
  8.     int s[5], vrh;
  9.  
  10.     void ini() {
  11.         vrh = 4;
  12.     }
  13.  
  14.     void push(int x) {
  15.         if(vrh == -1)
  16.             cout << "stog je pun" << endl;
  17.         else {
  18.             s[vrh] = x;
  19.             vrh--;
  20.         }
  21.     }
  22.  
  23.     int pop() {
  24.         if(vrh == 4)
  25.             cout << "stog je prazan" << endl;
  26.         else
  27.             vrh++;
  28.  
  29.         return s[vrh];
  30.     }
  31.  
  32.     void ispis() {
  33.         cout << endl;
  34.         int i;
  35.         for(i = vrh + 1; i <= 4; i++)
  36.             cout << s[i] << endl;
  37.     }
  38. };
  39.  
  40. int main() {
  41.     stog st;
  42.     int izb, x;
  43.     st.ini();
  44.     do {
  45.         cout << endl;
  46.         cout << "1. push" << endl;
  47.         cout << "2. pop" << endl;
  48.         cout << "9. izlaz" << endl;
  49.         cout << "___________" << endl;
  50.  
  51.         cin >> izb;
  52.         cout << endl;
  53.  
  54.         if(izb == 1) {
  55.             cout << "Unesi element: ";
  56.             cin >> x;
  57.             st.push(x);
  58.         }
  59.  
  60.         if(izb == 2) {
  61.             x = st.pop();
  62.             cout << "iz stoga izlazi: " << x << endl;
  63.         }
  64.  
  65.         st.ispis();
  66.     } while(izb != 9);
  67.  
  68.     system("PAUSE");
  69.     return 0;
  70. }
Add Comment
Please, Sign In to add comment