Last active
May 18, 2018 12:05
-
-
Save this-mkhy/7aa2ff6e6378d7db50ca29d6b6a5caa7 to your computer and use it in GitHub Desktop.
Stack in STL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stack> | |
using namespace std; | |
void printStack(stack <int> myStack) | |
{ | |
stack <int> s= myStack; | |
while (!s.empty()) | |
{ | |
cout<< s.top()<<endl; | |
s.pop(); | |
} | |
cout <<endl; | |
} | |
int main () | |
{ | |
stack <int> st; | |
st.push(10); | |
st.push(20); | |
st.push(30); | |
st.push(40); | |
st.push(50); | |
cout << "The stack st is : "<<endl; | |
printStack(st); | |
cout << "the stack size : " << st.size()<<endl; | |
cout << "the stack top : " << st.top()<<endl; | |
cout << "After pop element : "<<endl; | |
st.pop(); | |
printStack(st); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment