/***循环队列基本操作***/
#include<iostream>
#include<fstream>
using namespace std;
#define MAXQSIZE 100
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef char QElemType;
typedef char SElemType;
typedef int Status;
typedef struct {
QElemType *base;//初始化时动态分配存储空间
int front;//头指针
int rear;//尾指针
} SqQueue;
//算法 循环队列的初始化
Status InitQueue(SqQueue &Q) {
//构造一个空队列Q
Q.base = new QElemType[MAXQSIZE]; //为队列分配一个最大容量为MAXSIZE的数组空间
if (!Q.base)
exit(OVERFLOW); //存储分配失败
Q.front = Q.rear = 0; //头指针和尾指针置为零,队列为空
return OK;
}
//求循环队列的长度
int QueueLength(SqQueue Q) {
</
队列的各种操作
最新推荐文章于 2022-09-19 21:16:14 发布