循环顺序队列c++实现

一种重要的线性表叫做队列,是一种标准的FIFO类型的,就是先进先出,在计算机领域,这种数据结构有很广泛的应用,有一种一般形式的数组的队列实现,但是这种队列耗费空间,今天给大家介绍一种充分利用空间的队列,循环队列。


#include <iostream>

#include <cstdio>
#include <cstring>
#include <cstdlib>


using namespace std;


//循环队列最多100个元素
#define MAX 100
//循环队列的数据类型
typedef int QueueType;


class Queue
{
private:
    QueueType data[MAX];
    int front;//指向头部的下标
    int rear;//指向尾部的后一个,当rear=front的时候就代表队列为空
public:
    Queue();
    bool Empty();
    bool Full();
    bool DeQueue(QueueType &e);
    bool EnQueue(QueueType e);
    bool GetTop(QueueType &e);
};


Queue::Queue()
{
    this->front = this->rear = 0;
}
bool Queue::Empty()
{
    if(this->rear == this->front)
        return true;
    return false;
}
bool Queue::Full()
{
    if((this->rear+1)%MAX == this->front)
        return true;
    return false;
}
bool Queue::DeQueue(QueueType &e)
{
    if(Empty())
        return false;
    e = this->data[this->front];
    this->front = (this->front+1)%(MAX);
    return true;
}
bool Queue::EnQueue(QueueType e)
{
    if(Full())
        return false;
    this->data[this->rear] = e;
    this->rear = (this->rear+1)%MAX;
    return true;
}
bool Queue::GetTop(QueueType &e)
{
    if(Empty())
        return false;
    e = this->data[this->front];
    return true;
}


int main()
{
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值