// stack example
//
// - a stack is a first-in-last-out container adapter
// - when you insert an item, it goes to the bottom
// - when you take an item, you take from the top
// - the closet analogy is a stack of plates
// - see http://www.cppreference.com/cppstack.html

#include <stack>
#include <iostream>

using namespace std;

int main()
{
  stack<int> s; // create a stack of integers
             // top <--> bottom
  s.push(5); // 5
  s.push(4); // 4 5
  s.push(7); // 7 4 5
  s.push(9); // 9 7 4 5
  s.push(2); // 2 9 7 4 5
  s.push(3); // 3 2 9 7 4 5

  cout << "stack s has " << s.size() << " elements" << endl;

  cout << "stack s from the top contains ";
  while (!s.empty()) { // until the stack is not empty
    cout << s.top() << " "; // returns the top element
    s.pop();                // removes the top element
  }
  cout << endl;

  return 0;
}
