⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.h

📁 一个我的数据结构解题集合
💻 H
字号:
#ifndef QUEUE_H__
#define QUEUE_H__

#include "Vector.h"


template <typename T>
class Queue {
private:
	Vector<T> vec_;

public:

	/* 将元素e放入队列
	 */
	void push(const T&e) {
		vec_.pushBack(e);
	} // push(const T&)

	/* 将元素e弹出队列
	 */
	void pop() {
		vec_.removeFront();
	} // pop()

	/* 查询列首元素
 	 * 如果Queue为空, 抛出std::out_of_range异常
	 */
	const T& front() const {
		return vec_.front();
	} // front() const
	
	/* 查询位置为index的元素
	 * 如果index不满足 0 <= index && index < size(),
	 * 抛出out_of_range异常
	 * 提供const和非const两个版本
	 */
	T& operator[](int index) {
		return vec_[index];
	} // operator[](int)

	const T& operator[](int index) const {
		return vec_[index];
	} // operator[](int) const
	
	/* 预留至少capacity的空间
	 */
	void reserve(int capacity) {
		vec_.reserve(capacity);
	} // reserve(int)

	/* 查询预留空间的大小
	 */
	int capacity() const {
		return vec_.capacity();
	} // capacity() const

	/* 查询Queue中现存元素的数目
	 */
	int size() const {
		return vec_.size();
	} // size() const

	/* 查询Queue是否为空
	 */
	bool isEmpty() const {
		return vec_.isEmpty();
	} // isEmpty() const

}; // Queue



#endif // QUEUE_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -