C/C++数据结构之队列简单实现

---------------------------------------

编辑于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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值