队列的基本实现
来源:互联网 发布:金玉满堂 知乎 编辑:程序博客网 时间:2024/05/18 13:46
队列的基本实现
TIP:宏断言assert(<表达式>);
利用宏断言,如果不满足则说明队列空,直接返回;
#include <iostream>#include <cassert>using namespace std;class Queue {private: int *data; int head, tail, length;public: Queue(int length_input) { data = new int[length_input]; length = length_input; head = 0; tail = -1; } ~Queue() { delete[] data; } void push(int element) { if (tail + 1 < length) { tail++; data[tail] = element; } } void output() { for (int i = head; i <= tail; i++) { cout << data[i] << " "; } cout << endl; } int front(){ assert(head<=tail);//利用宏断言,如果不满足则说明队列空,直接返回 return data[head]; } void pop(){ assert(head<=tail); head++; }};int main() { Queue queue(100); for (int i = 1; i <= 10; i++) { queue.push(i); } queue.output(); cout<<queue.front()<<endl; queue.pop(); queue.output(); return 0;}
0 0
- 队列的基本实现
- 队列的基本实现
- 循环队列的基本实现
- 队列基本操作的实现
- 队列的基本运算实现
- 循环队列的基本实现
- 基本数据结构的python实现---队列
- 链队列基本运算的实现
- c实现队列的基本操作
- C++队列实现的基本操作
- 基本数据结构-队列的实现及其运用
- 栈和队列的基本操作实现
- C#实现队列的基本操作
- 用单链表的基本操作实现链队列
- 循环队列的基本操作实现
- 单链队列的基本操作实现
- 栈和队列的基本运算实现
- 顺序队列的基本操作实现c++
- PHP页面跳转三种实现方法
- Relationship between two numbers【2】
- 编程之美-数组除法
- Codeforces Round #354 (Div. 2) B Pyramid of Glasses(模拟)
- JDK的安装与配置
- 队列的基本实现
- EndNote使用方法
- codeforces 297D Color the Carpet(构造)
- HTTP的303、307状态码
- bash简单命令扩展
- java object类的方法
- Codeforces Round #354 (Div. 2) C Vasya and String(尺取法二分)
- iOS开发中使用平率很高的宏定义
- 《Head First C#》学习 ---第二章总结