 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Ordered Set and GNU C++ PBDS
In this tutorial, we will be discussing a program to understand ordered set and GNU C++ PBDS.
Ordered set is a policy based structure other than those in the STL library. The ordered set keeps all the elements in a sorted order and doesn’t allow duplicate values.
Example
#include <iostream> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int main(){    //declaring ordered set    ordered_set o_set;    o_set.insert(5);    o_set.insert(1);    o_set.insert(2);    cout << *(o_set.find_by_order(1))     << endl;    cout << o_set.order_of_key(4)     << endl;    cout << o_set.order_of_key(5)     << endl;    if (o_set.find(2) != o_set.end())     o_set.erase(o_set.find(2));    cout << *(o_set.find_by_order(1))     << endl;    cout << o_set.order_of_key(4)     << endl;    return 0; }  Output
2 2 2 5 1
Advertisements
 