이 튜토리얼에서는 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;
//initializing ordered set
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