Advertisement
vaibhav1906

Stacks

Dec 3rd, 2021
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     stack<int>st;
  6.     st.push(5); //5
  7.     st.push(1); //1,5
  8.     st.push(3); //3,1,5
  9.    
  10.     cout<<"Top element right now : "<<st.top()<<endl; //3
  11.     int a = st.top();
  12.     st.pop();
  13.     cout<<"We have just poped : "<<a<<endl;
  14.     cout<<"Top element right now : "<<st.top()<<endl; //1
  15.    
  16.     //To see all the elements of stack
  17.    
  18.     while(st.size()!=0){
  19.         cout<<st.top()<<" ";
  20.         st.pop();
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement