编写一个程序,实现顺序环形队列的各种基本运算。

这篇博客详细介绍了如何编写一个程序来实现顺序环形队列的各种基本运算,包括初始化队列、判断队列非空、元素进队、出队、输出元素个数以及释放队列等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

完成如下功能:

(1)初始化队列q;

(2)判断队列q是否非空;

(3)依次进队元素a,b,c;

(4)出队一个元素,并输出该元素;

(5)输出队列q的元素个数;

(6)依次进队列元素d,e,f;

(7)输出队列q的元素个数;

(8)输出出队序列;

(9)释放队列。



代码:

#include"iostream"
#define MaxSize 50
using namespace std;
class queue{
private:
char data[MaxSize];
    int front,rear;
static int count;
public:
     void initqueue(queue *&);
void destroyqueue(queue *&);
bool queueempty(queue *);
bool enqueue(queue *&,char);
static bool dequeue(queue *&);
static bool outqueue(queue *);
static int getcount(){ return count; }
};


int queue::count=0;


void queue::initqueue(queue *&q)
{
q=new queue;
q->front=q->rear=0;
}


void queue::destroyqueue(queue *&q)
{
free(q);
}


bool queue::queueempty(queue *q)
{
return(q->front==q->rear);
}


bool queue::enqueue(queue *&q,char e)
{
if((q->rear+1)%MaxSize==q->front)
return 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值