Advertisement
Aodai

GIT GUD MARIUS

Mar 8th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. ```cpp
  2. struct nod {
  3.     int inf;
  4.     nod *next;
  5. };
  6.  
  7. struct stiva {
  8.     nod*vf;
  9.     stiva()
  10.     {
  11.         vf = NULL;
  12.     }
  13.     void push(int k)
  14.     {
  15.         nod *y = new nod;
  16.         y->inf=k;
  17.         y->next = vf;
  18.         vf = y;
  19.     }
  20.     bool isEmpty()
  21.     {
  22.         if (vf == NULL)
  23.             return true;
  24.         else
  25.             return false;
  26.     }
  27.     void pop()
  28.     {
  29.         if (isEmpty() == false)
  30.         {
  31.             nod *y;
  32.             y = vf;
  33.             vf = vf->next;
  34.             delete y;
  35.         }
  36.         else
  37.             cout << "Stiva e goala ";
  38.     }
  39.     int top()
  40.     {
  41.         int k = vf->inf;
  42.         return k;
  43.     }
  44. };
  45.  
  46. int main()
  47. {
  48.     int n, m;
  49.     stiva S;
  50.     cin >> n;
  51.     for (int i = 0; i < n; i++)
  52.     {
  53.         cin >> m;
  54.         S.push(m);
  55.     }
  56.     for (int i = 0; i < n; i++)
  57.     {
  58.         m=S.top();
  59.         cout << m<<" ";
  60.          S.pop();
  61.     }
  62.     _getch();
  63. }
  64. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement