fork download
  1. //
  2. // main.cpp
  3. // Stack
  4. //
  5. // Created by Himanshu on 03/10/21.
  6. //
  7.  
  8. #include <iostream>
  9. #include <stack>
  10. using namespace std;
  11.  
  12. int main () {
  13.  
  14. stack<int> st;
  15.  
  16. cout<<"Push(x) {10, 20, 30, 40, 50}"<<endl;
  17. st.push(10);
  18. st.push(20);
  19. st.push(30);
  20. st.push(40);
  21. st.push(50);
  22.  
  23. cout<<"Stack-Empty(): ";
  24. if (st.empty()) {
  25. cout<<"Stack is empty"<<endl;
  26. } else {
  27. cout<<"Stack is not empty"<<endl;
  28. }
  29.  
  30. cout<<"Pop elements..."<<endl;
  31. while (!st.empty()) {
  32. cout<< st.top()<<" ";
  33. st.pop();
  34. }
  35. cout<<endl;
  36.  
  37. cout<<"Stack-Empty(): ";
  38. if (st.empty()) {
  39. cout<<"Stack is empty"<<endl;
  40. } else {
  41. cout<<"Stack is not empty"<<endl;
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 5544KB
stdin
Standard input is empty
stdout
Push(x) {10, 20, 30, 40, 50}
Stack-Empty(): Stack is not empty
Pop elements...
50 40 30 20 10 
Stack-Empty(): Stack is empty