Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Sets of pairs in C++
Set in C++ is an associative container and contains unique elements. All the elements once added to a specific cannot be modified. One can only remove and add elements in order to change them.
Pair is defined under
The order of pair elements is fixed (first, second). We can use pair to combine two heterogeneous values of different types.
To access any element we use variable_name.first for the first element and use variable_name.second for the second element of the pair.
Set of pairs in C++
- No duplicate pair is allowed in a set of pairs.
- Elements of such a set, i.e pairs are sorted according to the key that is the first element of each pair present in the set.
- We can search for a particular pair, add pair, remove pair and can get the count of pair present.
- Syntax is −
set > set_name;
set > set1;
Here , set1 is an object of type set which consists of pairs of two integer types.
Example
#includeusing namespace std; int main(){ //pair pairs; int arr[]={ 2, 3, 1, 6, 9, 7, 10, 2 }; int n=8; set > set1; for (int i = 0; i Output
(1, 7) (1, 9) (3, 1) (3, 7) (3, 9) (9, 7)
