跳到正文

算法·理论

数据类型

ZzZzz_shutdown_s约 3 分钟
原文
文章信息与版本

文章信息

发布
2024年1月26日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 3 分钟

版本

  1. v2当前
  2. v1

数据结构

栈

C++
stack</*类型*/>s;//定义栈
s.push();//压入元素
s.pop();//弹出元素
s.top();//查询栈顶元素
s.size();//查询栈内元素个数
s.empty();//查询栈是否为空

或手敲stack

C++
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;

队列

C++
#include<queue>
queue</*类型*/>q;
q.push();
q.front();//获取队首
q.back();//队尾
q.size();
q.empty();//查询队列是否为空
q.pop();

或手敲queue

C++
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;
	}
};

双端队列

C++
deque<int>d;
.push_back();
.push_front();
.pop_...
.back();
.front();
.clear();//清空
.begin()//首地址
.erase()//删除
.end()//队尾地址
deque<int>::iterator it;//定义指针

堆

优先队列

C++
#incude<queue>
priority_queue<int>p;//从大到小
priority_queue<int,vector<int>,greater<int> >//从小到大

map

C++
map</*类型*/,/*类型*/>mp;
unordered_map</*类型*/,/*类型*/>mp;

set

C++
set</*类型*/>s;
s.push_back(/*插入的数*/);
int x=lower_bound(s.begin(),s.end(),/*要查找的数*/);
s.erase(/*删除的下标*/);
multiset</*类型*/>ms;

vector

懒得讲了

广搜

queue

  • 将起始节点放入队列中,并标记为以访问

  • 进入循环,直到队列为空:

    1. 从队列中取出一个节点
    2. 访问该节点

ST表:

定义:从第i个数开始的2^j个数的最小值;代码如下:

原文