इस ट्यूटोरियल में, हम ऑर्डर्ड सेट और GNU C++ PBDS को समझने के प्रोग्राम पर चर्चा करेंगे।
ऑर्डर्ड सेट STL लाइब्रेरी के अलावा एक पॉलिसी-आधारित संरचना है। ऑर्डर्ड सेट सभी तत्वों को सॉर्टेड क्रम में रखता है और डुप्लिकेट मानों की अनुमति नहीं देता।
उदाहरण
#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(){ //ऑर्डर्ड सेट घोषित करना 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; }आउटपुट
2 2 2 5 1