C ++中的order_of_key()
在本教程中,我们将讨论一个程序,以了解C++中的order_of_key()。
函数order_of_key()接收一个键,并返回小于在有序集合中作为参数提供的键的元素数。
示例
#include <iostream>
using namespace std;
#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>
ordered_set;
int main(){
ordered_set mySet;
mySet.insert(5);
mySet.insert(2);
mySet.insert(6);
mySet.insert(4);
cout << "Count of elements less than 6::"<< mySet.order_of_key(6) << endl;
cout << "Count of elements less than 7 ::"<< mySet.order_of_key(7) << endl;
return 0;
}输出结果
Count of elements less than 6::3 Count of elements less than 7 ::4
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短