Standard Template Library- Containers
This is the built-in implementation of data structures named as containers. It is an object which holds the collection of other elements. Generally, it is implemented as template defined as class.
Main advantage is flexibility.
Types of containers can be classified as follows.
- 1. Associative containers
- 2. Unordered associative containers
- 3. Container adapter
- 4. Sequence containers
The built-in functions connected with each container are
explained below.
1.Associative containers:
From the
name itself, we can know. Association means the data storage have some connectivity.
It makes the access faster. So, the time is efficient here.
It has the following containers.
- Map - Here, the value and key are paired. One restriction is two pairs should not have same
- keys.
- Set - It has a collection of unique data sorted.
- Multiset – it has a collection of data. But multiple copies are allowed.
- Multimap – it combines the set and map together.
Next one is unordered associative containers.
2.Unordered Associative Containers:
It
deals with unsorted hashed data structures with quick searching method.it has
time complexity as O(1). The worst case complexity is O(n).
The containers used here is,
- Unordered set – it is set of unique elements with hash value.
- Unordered map – it has a key-value pair with unique keys.
- Unordered multiset – it has a multi set of data
- Unorderd multimap – it has a key-value pair with multiple values.
3.Container
Adapters
Container
adapters give you the different interface for accessing containers. mainly, it
deals with use cases.
- Stack: Stack follows a principle called “Last In First Out(LIFO)”.
- Queue : Queue is a data structure called “First In First “Out(FIFO)”.
- Priority Queue : it follows hash values to store the elements.
4.Sequence Containers:
It
creates linear data structures which access the data sequentially. The containers
in this category as follows.
- Array – it has static elements.
- List – it has a collection of elements.
- Deque – Dynamic queue which has two ends.
- Vector – it is a dynamic array that can be resizable.
- Forward List – it is singly linked list.
These are the built -in containers in STL. Hope, this explanation is useful to you. Keep Reading!!!
Comments
Post a Comment