![]() |
VOOZH | about |
In C++ Standard Template Library, set, multiset, unordered_set, unordered_multiset are used to store elements. Although they are similar but differ from each other in some functionalities. The differences are discussed below:
1. Set: Sets are associative containers that store unique elements following a specific order. Following are the properties of sets:
Syntax:
set<datatype> setname;
The following example demonstrates the application of set.
Set elements (Note : sorted and duplcayes removed) 2 10 12 45 85 90 Set Elements after erase: 2 90
2. Multisets: Multisets are associative containers that store multiple elements having equivalent values following a specific order. Following are the properties of multisets:
Note: All other properties are similar to the set.
Syntax:
multiset<datatype> multisetName;
The following example demonstrates the application of Multiset.
Multiset elements (Note : Sorted and duplicates allowed) 2 10 10 12 45 85 90 Multiset Elements after erase: 2 90
3. unordered_set: unordered_set are associative containers that store unique elements in no particular order. Following are the properties of Unordered_sets:
Note: All other properties are similar to the set.
Syntax:
unordered_set<datatype> setname;
The following example demonstrates the application of Unordered set.
Unordered_set elements (Note : Not sorted): 70 85 45 12 10 2 90 Unordered_set Elements after erase: 70 85 45 12 2 90
4. Unordered_multiset: Unordered_multiset is an associative container that contains a set of non-unique elements in unsorted order. Following are the properties of Unordered_multiset:
Note: All other properties are similar to the set.
Syntax:
unordered_multiset<datatype> multisetName;
The following example demonstrates the application of Unordered multiset.
Unordered-Multiset (Note : Elements are not sorted and duplciates are allowed : 85 45 12 90 2 10 10 Unordered-Multiset Elements after erase: 85 45 12 90 2 10
Difference between set, multiset, unordered_set, unordered_multiset: