A
stack
is a container that permits to insert and extract its elements only from the top of the container:
#include <cassert>
#include <stack>
usingnamespace std;
int main (int argc, char* argv[])
{
stack< int > st;
st.push( 100 ); // push number on the stack
assert( st.size() == 1 ); // verify one element is on the stack
assert( st.top() == 100 );// verify element value
st.top() = 456; // assign new value
assert( st.top() == 456 );
st.pop(); // remove element
assert( st.empty() == true );
return 0;
}