Tuesday, October 11, 2011

Exercise of STL stack

#include <iostream>
#include <stack>

using namespace std;

int main()
{
cout << "STL stack exercise" << endl << endl;

stack<int> MyStack;
cout << "init without anything" << endl;
cout <<"MyStack.size(): " << MyStack.size() << endl << endl;

cout << "push something in" << endl;
MyStack.push(1);
MyStack.push(2);
MyStack.push(3);
MyStack.push(4);
cout <<"MyStack.size(): " << MyStack.size() << endl << endl;

cout << "pop all out" << endl;
while (!MyStack.empty())
{
cout << MyStack.top() << endl;
MyStack.pop();
}

cout << endl << endl;

return 0;
}


Exercise of STL stack


No comments:

Post a Comment