点击目录传送ฅʕ•̫͡•ʔฅ
Algorithm
认识队列
#include<iostream>
using namespace std;
int main()
{
int q[124] = {
6, 3, 1, 7, 5, 8, 9, 2, 4}, head, tail;
//初始化队列
head = 0;
tail = 9; //队列中已经有9个元素了,tail指向队尾的后一个位置
while(head < tail) {
//打印队首并将队首出队
cout << q[head] << " ";
head++;
//将新队首的数添加到队尾
q[tail] = q[head];
tail++;
//新队首出队
head++;
}
getchar();
getchar();
return 0;
}
Run:
输出规则(将队首出队,新队首放到队尾,然后删除,重复执行)
将队列的三个基本元素(一个数组,两个变量)封装为一个结构体类型
#include<iostream>
using namespace std;
//队列的三个基本元素(一个数组,两个变量)
struct queue {
int data