#include<stdio.h>
//#include<string.h>
//#include<math.h>
#include<stdlib.h>
//函数结果状态代码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define NULL 0
#define MAXSIZE 100
#define MAXQSIZE 100
//Status是函数的类型,其值是函数结果状态代码
typedef int Status;
//声明结点的类型和指向结点的指针类型
typedef struct {
QElemType *base;//初始化的动态分配存储空间
int front;//头指针
int rear;//尾指针
}SqQueue;
//循环队列初始化
Status InitQueue(SqQueue &Q){
Q.base=(QElemType*)malloc(MAXQSIZE*sizeof(QElemType));//分配数组空间
if(!Q.base) exit(OVERFLOW);//存储分配失败
Q.front=Q.rear=0;//头指针尾指针指向0,队列为空
return OK;
}
//求队列长度
int QueueLength(SqQueue &Q) {
return((Q.rear-Q.front+MAXQSIZE)%MAXQSIZE);
}
//入队
Status EnQueue(SqQueue &Q,QElemType e){
if((Q.rear+1)%MAXQSIZE==Q.front) return ERROR;//队满
Q.base[Q.rear]=e;//新元素加入队尾
Q.rear=(Q.rear+1)%MAXQSIZE;//队尾指针+1
return OK;
}
//出队
Status DeQueue(SqQueue &Q,QElemType &e){
if(Q.front==Q.rear) return ERROR;//队空
e=Q.base[Q.front];//保存队头元素
Q.front=(Q.front+1)%MAXQSIZE;//队头指针+1
return OK;
}
//取队头元素
QElemType GetHead(SqQueue &Q){
if(Q.front!=Q.rear) //队列不为空
return Q.base[Q.front];
}
int main(){
return 0;
}