g ++编译器是Linux中GNU的C ++编译器。
g ++编译器还增加了对某些不在C ++编程语言标准库中的特殊数据结构的支持。这些被称为基于策略的数据结构。
与C ++ std库的标准数据结构相比,基于策略的数据结构为程序员提供了高性能,语义安全性和灵活性。
为了将这些数据结构包括到您的程序中,应添加以下几行,
#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
让我们看一个程序,看看这些基于策略的数据结构如何工作。
#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>
new_data_set;
int main() {
new_data_set data;
data.insert(34);
data.insert(785);
data.insert(12);
data.insert(87);
cout<<"The value at index 2 is "<<*data.find_by_order(2)<<endl;
cout<<"The index of number 87 is "<<data.order_of_key(87)<<endl;
return 0;
}输出结果
The value at index 2 is 785 The index of number 87 is 4
这些数据结构用途广泛,您可以使用许多功能,例如检查元素的索引,在索引处查找元素等。