Container Classes
Up to now, the data structures we've used: linked-lists, stacks, and queues, are those we've built ourselves. If these structures are so useful---and they are---why are they not part of the language?
They are implementations, not language constructs
They have many variants. For example, consider the different kinds of queues:
In type:
Queue of characters
Queue of integers
Queue of __________
In characteristics:
Simple queue
Priority queue (w/multiple priority schemes)
Double-ended queue
However, the usefulness of common data structures has encouraged a standardization for these data structures in the C++ Standard Template Library (or STL).
The STL provides many common data structures for managing (or containing) objects, including: vectors, lists, stacks, queues, priority queues, sets, and maps.
STL data structures are templates, meaning they are incomplete implementations until a C++ object type is provided by the programmer to indicate the objects which they operate upon.
Example: lists are sequences of objects, so if we want a sequence of float objects, we specify: list<float>. If we want a list of complex_number then we specify: list<complex_number>. Get it?
Template implementations are very powerful. They have some limitations and some special rules, but we can ignore that for now (we'll look at them in depth more later) and just take advantage of them.
Here are the STL data structures we'll look at (in this order):
vector: provides dynamic resizing and random access to a collection of like objects.
list: provides dynamic resizing, combining, and sorting of the list(s).
stack: provides the LIFO behavior of adding to and removing from the stack.
queue: provides the FIFO behavior of adding to and removing from the queue.