循环队列的9种基本操作

循环队列的9种基本操作

定义常量

/*一些经常用到的头文件,预定义常量等*/
//常用头文件
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
//函数结果状态代码
#define TRUE	1
#define FALSE	0
#define OK		1
#define ERROR	0
#define INFEASIBLE	0
//新建函数类型,表示函数运行结果
typedef int Status;

结构体定义和函数声明

#define MAXQSIZE 10
typedef int QElemType;
typedef struct
{
   
	QElemType* base;
	int front;
	int rear;
}SqQueue;

//构造空队列
Status InitQueue(SqQueue* Q);
//销毁队列
Status DestroyQueue(SqQueue* Q);
//清空队列 
Status ClearQueue(SqQueue* Q);
//判队列空
Status QueueEmpty(SqQueue Q);
//队列长度
int QueueLength(SqQueue Q);
//取队头元素,用e返回
Status GetHead(SqQueue Q, QElemType* e);
//插入元素
Status EnQueue(SqQueue* Q, QElemType e);
//删除元素
Status DeQueue(SqQueue* Q, QElemType* e);
//遍历队列
Status QueueTraverse(SqQueue Q, void (*visit)(QElemType));

//辅助函数
void visit(QElemType e);

函数定义

//构造空队列
Status InitQueue(SqQueue* Q)
{
   
	Q->base = (QElemType*)malloc(MAXQSIZE * 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值