很好理解,队列就是把数据排成队,先到的排在前面,后到的排在后面,走的时候,在前面的先出去。(不许插队!)
先是顺序队列,也就是基本的排成一队。
实现如下:
#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) { //后来的数据会排在队列的末尾