Skip to content

Instantly share code, notes, and snippets.

@this-mkhy
Last active May 18, 2018 12:05
Show Gist options
  • Save this-mkhy/7aa2ff6e6378d7db50ca29d6b6a5caa7 to your computer and use it in GitHub Desktop.
Save this-mkhy/7aa2ff6e6378d7db50ca29d6b6a5caa7 to your computer and use it in GitHub Desktop.
Stack in STL
#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