pb_ds (平板电视???)
pb_ds 是GNU-C++自带的一个C++的扩展库,其中实现了很多数据结构,比STL里面的功能更强大
(Ex.#include <ext/pb_ds/assoc_container.hpp>)
哈希表
头文件
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
两种定义方式
cc_hash_table<string,int>mp1;//拉链法
gp_hash_table<string,int>mp2;//查探法(快于上一个)
堆
pb_ds库的堆提供了五种tag,分别是 pairing_heap_tag, binary_heap_tag ,binomial_heap_tag , rc_binomial_heap_tag ,thin_heap_tag。因为重名的原因要加上 __gnu_pbds::
#include<ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
__gnu_pbds::priority_queue<int>q;
__gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag>pq;//最快
__gnu_pbds::priority_queue<int,greater<int>,binary_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>,binomial_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>,rc_binomial_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>,thin_heap_tag>pq;
__gnu_pbds::priority_queue<int,greater<int>>pq;
基本操作
push() //会返回一个迭代器
top() //同 stl
size() //同 stl
empty() //同 stl
clear() //同 stl
pop() //同 stl
join(priority_queue &other) //合并两个堆,other会被清空
split(Pred prd,priority_queue &other) //分离出两个堆
modify(point_iterator it,const key) //修改一个节点的值
优先队列迭代器
__gnu_pbd::priority_queue<int>::point_iterator it;
红黑树
头文件
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
…