pb_ds库的用法

13 篇文章 1 订阅

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;

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值