Container Adaptors

Computer system analysis is like child-rearing; you can do grievous damage, but you cannot ensure success. Tom DeMarco


Language C++ | Level Intermediate | Category Standard Template Library (STL) | 2015-11-17 04:17:30



Stack is a data structure store and remove the items based on last in and first out. Priority queues are implemented based on container.


Last-in, first-out (LIFO) data structure.
The stack insert into the top and removed from the top.
Stack can be implemented using array or linked list (dynamic memory)
If the stack is full and does not contain enough space to accept an entity to be pushed, the stack is then considered to be in an overflow state.
If the stack is empty, it goes into underflow state.

source Code

#include "stdafx.h"

#include < iostream >
#include < stack >
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
	stack < int > st;
	cout << "Store items to stack." << endl;

	for (int i = 0; i < 10;i++)
	cout << "Stack size : " << st.size() << endl;
	cout << "Display items from stack : " << st.size() << endl;
	while (!st.empty())
		int w =;
		cout << w << " ";

	cout << endl;

	return 0;



					Store items to stack.
					Stack size : 10
					Display items from stack : 10
					9 8 7 6 5 4 3 2 1 0

When to use

If you want insert and remove the items using last in first out (LIFO) order, you can use Stack.


Please login to add comments.