有序集和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 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短