Standard Template Library
Standard Template Library is a collection of template classes and functions ( discussed in the previous section ) that provide common data structures and algorithms. The STL is designed to provide generic and efficient implementations of common data structures (like vectors, lists, queues, and stacks) and algorithms (like sorting, searching, and manipulating sequences). It enables a C++ programmer to use these data structures without writing them from scratch. These are more optimized and save development time. That is why using STL is a better decision. They are mostly used in competitive programming where time is short.
Components of STL
STL has three components.
- Containers
- Algorithms
- Iterators
Containers
Containers are data structures that store and manage collection of objects.
Containers are further:
- Sequence containers - Array, vectors, deque etc.
- Container Adaptors - Stacks, Queues, Priority Queues
- Associative Containers - Set, Map, Multiset, Multimap
- Unordered Associative - Unordered Set, Unordered Map, Unordered Multiset, Unordered Multimap
Algorithms
Algorithms are set of instructions ( not code ) that perform various operations on sequences of elements. Some commonly used algorithms are:
- Sort
- Find
- Accumulate
- Reverse
- Binary
- Search
Iterators
Iterators provide a way to access the elements of a container in a generic and uniform manner. They act like pointers to elements in the container and allow traversal through the container's elements.
Practice Exercises
Complete these exercises to reinforce your learning and earn XP