STL Programing Model
The STL is divided into three parts. They are containers, algorithms, and iterators. All these three parts can be used for different programming problems, and are closely associated with one another.
a. Containers: A container is an object that contains data or other objects. The standard C++ library has a number of container classes that allows the programmer to perform common tasks. These containers support generic programming and can be used for handling the data of different data types. All STL container classes are declared in namespace std; There are two types of containers, as shown in Figure 20.1: sequence container and associative container. Sequence containers are created to allow sequential and random access to members. Associative containers allow access to their elements through a key.
b. Algorithms: An algorithm is a technique that is useful to handle the data stored in containers. The STL comprises approximately 60 standard algorithms that give support to perform frequent and primary operations such as copying, finding, sorting, merging, and initializing. The standard algorithms are defined in the header file <alogrithm>.
c. Iterators: An iterator is an object. It behaves exactly similar to a pointer. It indicates or points to the data element in a container. It is utilized to move between the data items of containers. Iterators can be incremented or decremented similar to pointers. They link algorithms with containers and handle the data stored in the containers.