#include
#define MAXQSIZE 100
#define OK 1
#define ERROR 0
#define OVERFLOW -1
typedef int QElemType;
typedef int Status;
using namespace std;
typedef struct{
QElemType *base;
int front;
int rear;
}SqQueue;
//循环队列的初始化
Status InitQueue(SqQueue &Q){
Q.base=new QElemType[MAXQSIZE];
if(!Q.base) exit(OVERFLOW);
Q.front=Q.rear=0;
return OK;
}
//入队
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;
return OK;
}
//打印队列元素
Status printQueue(SqQueue Q){
QElemType e;
while(Q.front!=Q.rear){
e=Q.base[Q.front];
cout<>n;
cout<<"请输入队列中的各个元素:"<>e;
EnQueue(Q,e);
}
cout<<"此时队列中有"<<(Q.rear-Q.front+MAXQSIZE)%MAXQSIZE<<"个数据元素,如下所示:"<>x;
EnQueue(Q,x);
cout<<"此时队列中有"<<(Q.rear-Q.front+MAXQSIZE)%MAXQSIZE<<"个数据元素,如下所示:"<
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)