Sequential Container :
Sequential containers are those data structures that store data sequentially, hence elements are accessed sequentially.
These are some sequential container like
1. ARRAY: It is used to stores data of the same types like ar[int], arr[char]... It has a fixed size.
2. VECTOR: It can grow dynamically(size can grow automatically as elements increase ) and fast random access are also there.
3. dequeue : It is doubly ended queue and supports insertion and deletion from front and back both side. as well as fast random access is also there.
4. List : it is a doubly-linked list library in c++. Doubly linked list provides the functionality of deletion and insertion faster in O(1) time.
Associative Container : These types of containers like map , set , multimap , multiset.
1.map : It contains that data in key - value pair and key must be unique and ordered map supports accessing element in O(long) and allow accessing of elements in constant time in O(log n) time .
2. set : set contains all the unique elements and supports insert in o(n) but searching is fast in O(log n).
3. multiset : Same as set but here duplicate elements can be also there.
4 .multimap: it is same as map but key need not to be unique
NOTE : most of the insertion and deletion and searching in associative containers have time complexity of O(log n)
unordered STL containers : These containers are like unordered_map, unordered_set, unordered_multiset ,unordered_multimap.
General purpose STL algorithms are not sufficient because we can have to do modification under some of the code to implement some new things , but in stl they are pre-implemented so we can only use it is difficult to modify the STL library.
eg. of deueue of stl
#include<bits/stdc++.h>
using namespace std;
int main()
{
deque<int>dq; // define doubly ended queue from
STL directly
dq.push_back(1); // to push element in back of
queue
dq.push_back(2); // to push front of queue
dq.pop_front(); // to pop element from front
dq.push_front(5); // to push front of queue
dq.push_back(8); // to push element in back of
queue
for(int x:dq)
cout<<x<<" ";
return 0;
}
Output: 5 2 8
Get Answers For Free
Most questions answered within 1 hours.