有序集和GNU C ++ PBDS
在本教程中,我们将讨论一个程序来理解有序集和GNUC++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
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短