Rakibul_Ahasan

Stack_STL

Aug 22nd, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. // CPP program to demonstrate working of STL stack
  2. #include <iostream>
  3. #include <stack>
  4. using namespace std;
  5.  
  6. void showstack(stack <int> s)
  7. {
  8.     while (!s.empty())
  9.     {
  10.         cout << '\t' << s.top();
  11.         s.pop();
  12.     }
  13.     cout << '\n';
  14. }
  15.  
  16. int main ()
  17. {
  18.     stack <int> s;
  19.     s.push(10);
  20.     s.push(30);
  21.     s.push(20);
  22.     s.push(5);
  23.     s.push(1);
  24.  
  25.     cout << "The stack is : ";
  26.     showstack(s);
  27.  
  28.     cout << "\ns.size() : " << s.size();
  29.     cout << "\ns.top() : " << s.top();
  30.  
  31.  
  32.     cout << "\ns.pop() : ";
  33.     s.pop();
  34.     showstack(s);
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment