1// Program showing a policy-based data structure.
2#include <ext/pb_ds/assoc_container.hpp> // Common file
3#include <ext/pb_ds/tree_policy.hpp>
4#include <functional> // for less
5#include <iostream>
6using namespace __gnu_pbds;
7using namespace std;
8
9// a new data structure defined. Please refer below
10// GNU link : https://goo.gl/WVDL6g
11typedef tree<int, null_type, less<int>, rb_tree_tag,
12 tree_order_statistics_node_update>
13 new_data_set;
14
15// Driver code
16int main()
17{
18 new_data_set p;
19 p.insert(5);
20 p.insert(2);
21 p.insert(6);
22 p.insert(4);
23
24 // value at 3rd index in sorted array.
25 cout << "The value at 3rd index ::"
26 << *p.find_by_order(3) << endl;
27
28 // index of number 6
29 cout << "The index of number 6::"
30 << p.order_of_key(6) << endl;
31
32 // number 7 not in the set but it will show the
33 // index number if it was there in sorted array.
34 cout << "The index of number seven ::"
35 << p.order_of_key(7) << endl;
36
37 return 0;
38}
1#include <ext/pb_ds/assoc_container.hpp>
2#include <ext/pb_ds/tree_policy.hpp>
3
4using namespace __gnu_pbds;
5
6typedef tree<int, null_type, less<int>, rb_tree_tag,
7 tree_order_statistics_node_update>
8 ordered_set;
9
10ordered_set ord_set;
11
12int a;
13ord_set.insert(a);
14*ord_set.find_by_order(a);
15ord_set.order_of_key(a);