---------------------------------------
编辑于2020.03.06
---------------------------------------
最近用到了队列,下面就用代码实现一个最简单的队列。
在此不讨论其他复杂的方法,仅使用数组来实现,目的在于通过代码能了解队列先入先出的特性。
Show the codes:
---------------------------------------START-------------------------------------------------------------
queue.cpp
----
#include <iostream>
#define uint unsigned int
#define MENU 0
#define INIT_QUEUE 1
#define EN_QUEUE 2
#define DE_QUEUE 3
#define ERROR_NUM 999
using namespace std;
//初始化队列
int InitQueue(uint* inst, uint amount)
{
if (amount > 0 && amount < 65535)
{
memset(inst, 0, amount);
}
return 0;
}
//判断队列是否已初始化
bool CheckQueueInitialized(uint* inst, uint amount)
{
uint count = 0;
while (count < amount) {
if (*(inst + count) == 0) count++;
else break;
}
return (amount == count);
}
//判断队列已满
bool QueueNotFull(uint* inst, uint amount)
{
uint index = 0;
while (index < amount && *(inst + index) != 0)
{
index++;
}
return index<amount;
}
//获取队列中数据的数量
uint QueueElementCount(uint* inst, uint amount)
{
uint index = 0;
while