有序集和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 女生 节日祝福语简短大气