Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Containers in C++ STL (Standard Template Library)

  • Difficulty Level : Medium
  • Last Updated : 19 Nov, 2021

A container is a holder object that stores a collection of other objects (its elements). They are implemented as class templates, which allows great flexibility in the types supported as elements. 

The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators (reference objects with similar properties to pointers). 

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

Sequence containers

Sequence containers implement data structures that can be accessed sequentially. 

  • array: Static contiguous array (class template)
  • vector: Dynamic contiguous array (class template)
  • deque: Double-ended queue (class template)
  • forward_list: Singly-linked list (class template)
  • list: Doubly-linked list (class template)

Associative containers

Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity). 

  • Set: Collection of unique keys, sorted by keys 
    (class template)
  • Map: Collection of key-value pairs, sorted by keys, keys are unique (class template).
  • multiset: Collection of keys, sorted by keys (class template)
  • multimap: Collection of key-value pairs, sorted by keys 
    (class template)

Unordered associative containers

Unordered associative containers implement unsorted (hashed) data structures that can be quickly searched (O(1) amortized, O(n) worst-case complexity). 

Container adaptors

Container adaptors provide a different interface for sequential containers. 

  • stack: Adapts a container to provide stack (LIFO data structure) (class template).
  • queue: Adapts a container to provide queue (FIFO data structure) (class template).
  • priority_queue: Adapts a container to provide priority queue (class template). 

Flowchart of Adaptive Containers and Unordered Containers

Flowchart of Sequence conatiners and ordered containers

More Useful Links 

To master C++ Standard Template Library (STL) in the most efficient and effective way, do check out this C++ STL Online Course by GeeksforGeeks. The course covers the basics of C++ and in-depth explanations to all C++ STL containers, iterators, etc along with video explanations of a few problems. Also, you’ll learn to use STL inbuilt classes and functions in order to implement some of the complex data structures and perform operations on them conveniently.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!