- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Policy-based data structures in g++
g++ compiler is a C++ compiler for GNU in Linux.
The g++ compiler also adds support for some special data structures that are not in C++ programming language standard library. These are known as policy-based data structures.
The policy-based data structures provide the programmer a high-performance, semantic safety and flexibility as compared to the standard data structures of C++ std library.
To include these data structures to your program, the following lines should be added,
#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
Example
Let’s see a program to see how these policy-based data structures work.
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <iostream> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; int main() { new_data_set data; data.insert(34); data.insert(785); data.insert(12); data.insert(87); cout<<"The value at index 2 is "<<*data.find_by_order(2)<<endl; cout<<"The index of number 87 is "<<data.order_of_key(87)<<endl; return 0; }
Output
The value at index 2 is 785 The index of number 87 is 4
These data structures are so versatile that you can go for many functions like checking index of element, finding elements at index, etc.
Advertisements
To Continue Learning Please Login
Login with Google