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.

  1. Containers
  2. Algorithms
  3. Iterators

Containers

Containers are data structures that store and manage collection of objects.

Containers are further:

  1. Sequence containers - Array, vectors, deque etc.
  2. Container Adaptors - Stacks, Queues, Priority Queues
  3. Associative Containers - Set, Map, Multiset, Multimap
  4. 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:

  1. Sort
  2. Find
  3. Accumulate
  4. Reverse
  5. Binary
  6. 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

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

Which of the following is a best practice in programming?

10 XP~2 min
Exercise 2 of 2Easy

Code that is easy to read and understand is called ___ code.

10 XP~2 min