跳到正文

算法·理论

手打queue(class)

wzxuhaiqi约 1 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

最近几天学习了队列,就想用class手打,这样可以不用STL的队列,还能再改,代码贴出来,分享给大家,也能给自己做个记录(可能不对,有大神可帮改一下)

C++
class queue{
	const int mcx=1e6+5;
	int q[mcx],h=1,t=0;
public:
	void push(int x){
		q[++t]=x;
	}
	int front(){
		return q[h];
	}
	void pop(){
		h++;
	}
	int size(){
		return t-h+1;
	}
	bool empty(){
		return h=t+1;
	}
};
原文