1.队列queue:
#include<queue>
queue<int> que;
que.push(x);
que.front();
que.top();
que.pop();
que.size()
2.栈stack:
#include<stack>
stack<int> sta;
sta.push(x);
sta.front();
sta.top();
sta.pop();
sta.size()
3.优先队列(堆)priority_queue:
代码:
#include<queue>
priority_queue<int> heap;
heap.push(x);
heap.top();
heap.pop();
heap.size();
heap.empty();
结构体堆 :
struct rec {
int l,r;
}
priority_queue<rec> heap;
4.广义数组(平衡树)map:
代码:
#include<map>
map<int,int> ma;
ma[a]=b;
注意:
(1) 第一个int为下标类型,第二个int为数组类型
(2) 通常用于查询字符串或特殊字符出现次数
(3) 查询与修改时间复杂度为O(log n),n为当前数组的元素个数
5.算法(algorithm):
(1) 头文件:#include algorithm
(2) 代码:
min(a,b)
max(a,b)
swap(a,b)
sort(z+1,z+n+1)
reverse(z+1,z+n+1)
min_element(z+1,z+n+1)
max_element(z+1,z+n+1)
unique(z+1,z+n+1)
random_shuffle(z+1,z+n+1)
next_permutation(z+1,z+n+1)
prev_permutation(z+1,z+n+1);
quick_sort(z+1,z+n+1);
heap_sort(z+1,z+n+1);
merge_sort(z+1,z+n+1);
bool cmo(int a,int b)
int x=lower_bound(z+1,z+1+n,r)-z;
int x=upper_bound(z+1,z+1+n,r)-z;
6.动态数组(vector):
(1) 缺点:花费时间多,静态数组可以实现其所有功能
(2) 优点:节省空间
(3) 代码:
#include<vector>
using namespace std;
int x[2333];
vector<int> z;
int main()
{
z.resize(23333);
z[233]=2333;
z.push_back(2333);
}
7.双端队列(deque):
(1) 功能:可实现单调队列
(2) 代码:
#include<deque>
using namespace std;
deque<int> q;
int main()
{
q.push_front(1);
q.push_back(2);
q.pop_front();
q.pop_back();
q.front();
q.back();
q.size();
}