Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int const N = 20;
  5. int stack[N];
  6. int index = -1;
  7.  
  8.  
  9. bool IsEmpty()
  10. {
  11.         return(index == -1);
  12. }
  13.  
  14. void Push(int item)
  15. {
  16.     if(index<N-1)
  17.     {
  18.         index++;
  19.         stack[index] = item;
  20.     }
  21.     else
  22.     {
  23.         cout << "Preteceni" << endl;
  24.     }
  25. }
  26.  
  27.  
  28. int Top()
  29. {
  30.     if(!IsEmpty)
  31.     {
  32.         return stack[index];
  33.     }
  34.     else
  35.     {
  36.         cout << "Podteceni" << endl;
  37.         return -1;
  38.     }
  39. }
  40.  
  41. int Pop()
  42. {
  43.     if(!IsEmpty)
  44.     {
  45.         int ret=Top();
  46.         index--;
  47.         return ret;
  48.     }
  49.     else
  50.     {
  51.         cout << "Podteceni" << endl;
  52.         return -1;
  53.     }
  54. }
  55.  
  56. int main(){
  57.  
  58.     //Push(5);
  59.     /*for(int i=0; i<=N; i++)
  60.     {
  61.     Push(i);
  62.     }*/
  63.     cout << Top() << endl;
  64.     cout << Pop() << endl;
  65.     cout << IsEmpty();
  66.  
  67.  
  68. getchar();
  69. getchar();
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement