Concept of Set can be understood by following code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include<set>
usingnamespacestd;intmain(){// your code goes here
set<pair<int,int>>S;set<pair<int,int>>::iteratorit;S.insert({2,100});S.insert({1,200});S.insert({1,50});for(it=S.begin();it!=S.end();it++){cout<<(*it).first<<" "<<(*it).second<<endl;}return0;}
Output:
1 50
1 200
2 100
This property of set can be easily utilized, that set keeps all its elements in kind of sorted order. (using Red-Black Trees)
Psuedocode from CLRS :