|
12 | 12 | c++ STL containers
|
13 | 13 | ]
|
14 | 14 | description: In this tutorial, we'll explore STL containers in C++. We'll cover the different types of Standard Template Library containers, including vectors, lists, deques, sets, maps, and more. You'll learn how to choose the appropriate container for your needs and how to use their various functions and methods. Understanding STL containers is essential for effective data management and manipulation in C++ programs, providing you with powerful tools to handle collections of data efficiently.
|
15 |
| ---- |
| 15 | +--- |
| 16 | + |
| 17 | +## Introduction |
| 18 | + |
| 19 | +Containers can be described as the objects that hold the data of the same type. Containers are used to implement different data structures for example arrays, list, trees, etc. |
| 20 | + |
| 21 | +## Types of STL Containers |
| 22 | + |
| 23 | +- **Vector:** Vector is a class that creates a dynamic array allowing insertions and deletions at the back. |
| 24 | + Header File: `<vector>` |
| 25 | + |
| 26 | +- **List:** List is the sequence containers that allow the insertions and deletions from anywhere. |
| 27 | + Header File: `<list>` |
| 28 | + |
| 29 | +- **Deque:** Deque is the double ended queue that allows the insertion and deletion from both the ends. |
| 30 | + Header File: `<deque>` |
| 31 | + |
| 32 | +- **Set:** Set is an associate container for storing unique sets. |
| 33 | + Header File: `<set>` |
| 34 | + |
| 35 | +- **Multiset:** Multiset is an associate container for storing non- unique sets. |
| 36 | + Header File: `<set>` |
| 37 | + |
| 38 | +- **Map:** Map is an associate container for storing unique key-value pairs, i.e. each key is associated with only one value(one to one mapping). |
| 39 | + Header File: `<map>` |
| 40 | + |
| 41 | +- **Multimap:** Multimap is an associate container for storing key- value pair, and each key can be associated with more than one value. |
| 42 | + Header File: `<map>` |
| 43 | + |
| 44 | +- **Stack:** It follows last in first out(LIFO). |
| 45 | + Header File: `<stack>` |
| 46 | + |
| 47 | +- **Queue:** It follows first in first out(FIFO). |
| 48 | + Header File: `<queue>` |
| 49 | + |
| 50 | +- **Priority-queue:** First element out is always the highest priority element. |
| 51 | + Header File: `<queue>` |
| 52 | + |
| 53 | + |
| 54 | +## Choosing the Right Container |
| 55 | + |
| 56 | +Here are some general guidelines for choosing the appropriate container: |
| 57 | + |
| 58 | +1. Sequential containers are used to store elements in a linear order. They include arrays, vectors, deques, lists, and forward lists. |
| 59 | + |
| 60 | +2. Associative containers are used to store elements in a key-value relationship. They include maps, multimaps, sets, and multisets. |
| 61 | + |
| 62 | +3. Container adapters provide a different interface to an existing container. They include stacks, queues, and priority queues. |
| 63 | + |
| 64 | +Understanding STL containers is essential for effective data management and manipulation in C++ programs, providing you with powerful tools to handle collections of data efficiently. |
0 commit comments