Skip to content

Commit

Permalink
stack in stl c++
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijadhav03 authored Jun 5, 2024
1 parent ffafaf0 commit 167953a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions STL/stack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
void explainstack(){
stack<int> st;
st.push(1); //{1}
st.push(2); //{2,1}
st.push(3); //{3,2,1}
st.push(3); //{3,3,2,1}
st.empplace(5); //{5,3,3,2,1}
cout<< st.top(); //prints 5 **st[2] is invalid**
st.pop(); // st looks like {3,3,2,1}
cout<< st.top(); //3
cout<< st.size(); //4
cout<< st.empty();
stack<int> st1,st2;
st1.swap(st2);



}

0 comments on commit 167953a

Please sign in to comment.