数据类型
数据结构
栈
stack</*类型*/>s;//定义栈
s.push();//压入元素
s.pop();//弹出元素
s.top();//查询栈顶元素
s.size();//查询栈内元素个数
s.empty();//查询栈是否为空
或手敲stack
struct stack{
int b[1000005],t=1;
void push(int x){
if(t<=1000000)
b[t++]=x;
}
void pop(){
if(t>1)
t--;
}
int top(){
return b[t-1];
}
bool empty(){
if(t==1)return true;
else return false;
}
int size(){
return t-1;
}
void clean(){
t=1;
}
}s;
队列
#include<queue>
queue</*类型*/>q;
q.push();
q.front();//获取队首
q.back();//队尾
q.size();
q.empty();//查询队列是否为空
q.pop();
或手敲queue
struct queue{
int q[10000005];
int h=1,tail=0;
void push(int x){
tail++;
q[tail]=x;
}
void pop(){
h++;
}
int head(){
return q[h];
}
int size(){
return tail-h+1;
}
bool empty(){
return h>tail;
}
};
双端队列
deque<int>d;
.push_back();
.push_front();
.pop_...
.back();
.front();
.clear();//清空
.begin()//首地址
.erase()//删除
.end()//队尾地址
deque<int>::iterator it;//定义指针
堆
优先队列
#incude<queue>
priority_queue<int>p;//从大到小
priority_queue<int,vector<int>,greater<int> >//从小到大
map
map</*类型*/,/*类型*/>mp;
unordered_map</*类型*/,/*类型*/>mp;
set
set</*类型*/>s;
s.push_back(/*插入的数*/);
int x=lower_bound(s.begin(),s.end(),/*要查找的数*/);
s.erase(/*删除的下标*/);
multiset</*类型*/>ms;
vector
懒得讲了
广搜
queue
-
将起始节点放入队列中,并标记为以访问
-
进入循环,直到队列为空:
- 从队列中取出一个节点
- 访问该节点
ST表:
定义:从第i个数开始的2^j个数的最小值;代码如下: