Hello :)
I have just read in the book I learn STL from, a chapter called "Container adapters" which include stack, queue, and priority_queue. I understood how these work (LIFO/FIFO), how both stack and queue use deque as internal container, and have tested this containers in some programs.
Now my question is: What are these good for ? When should I use these instead of vector/deque/list ?
LIFO and FIFO refer to the way that data is handled, or the data structure. Different operations require that data be accessed in different ways, whether randomly or sequentially. Two types of sequential data structures are stacks and queues, which follow LIFO and FIFO principles, respectively.
A stack data structure can be imagined like a stack of papers, with new data always being added to the top of the stack. When data is removed from the stack, it is also taken from the top. In a word processing program, the "Undo" function uses this type of structure, where the most recently made change is the first one to be removed.
A queue operates on the first-in, first-out principle. Data is always added to the end of the queue and removed from the beginning. For example, if a number of people in an office all want to print using the same printer, the software would put each request into a queue and handle them on a first-come, first-served basis.
container is a holder object that stores a collection of other objects (its elements). They are implemented as class templates, which allows a great flexibility in the types supported as elements.
stack, queue and priority_queue are implemented as container adaptors. Container adaptors are not full container classes, but classes that provide a specific interface relying on an object of one of the container classes (such as deque or list) to handle the elements. The underlying container is encapsulated in such a way that its elements are accessed by the members of the container adaptor independently of the underlying container class used.