帮我用c++语言完善下列程序,#include <iostream> using namespace std; #define OK 1 #define ERROR 0 typedef int Status; typedef int ElemType; const int MAXSIZE=100; typedef struct { ElemType *base; int front; int rear; }SeqQueue; void InitQueue( SeqQueue &Q ) {//申请队列Q的数据区,构建空的循环队列 } Status EnQueue( SeqQueue &Q,ElemType x) { // 入队 } Status DeQueue( SeqQueue &Q,ElemType &e) { // 出队 } bool QueueEmpty(SeqQueue &Q) { //判队空 } bool QueueFull(SeqQueue &Q) {//判队满 } void DestroyQueue( SeqQueue &Q) // 销毁 { if(Q.base) { delete []Q.base; Q.base=NULL; Q.front=Q.rear=0; } }
时间: 2023-07-16 10:12:26 浏览: 94
#include <iostream>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef int ElemType;
const int MAXSIZE = 100;
typedef struct {
ElemType *base;
int front;
int rear;
} SeqQueue;
void InitQueue(SeqQueue &Q) {
//申请队列Q的数据区,构建空的循环队列
Q.base = new ElemType[MAXSIZE];
Q.front = Q.rear = 0;
}
Status EnQueue(SeqQueue &Q, ElemType x) {
// 入队
if ((Q.rear + 1) % MAXSIZE == Q.front) {
// 队满
return ERROR;
}
Q.base[Q.rear] = x;
Q.rear = (Q.rear + 1) % MAXSIZE;
return OK;
}
Status DeQueue(SeqQueue &Q, ElemType &e) {
// 出队
if (Q.front == Q.rear) {
// 队空
return ERROR;
}
e = Q.base[Q.front];
Q.front = (Q.front + 1) % MAXSIZE;
return OK;
}
bool QueueEmpty(SeqQueue &Q) {
//判队空
return Q.front == Q.rear;
}
bool QueueFull(SeqQueue &Q) {
//判队满
return (Q.rear + 1) % MAXSIZE == Q.front;
}
void DestroyQueue(SeqQueue &Q) {
// 销毁
if (Q.base) {
delete[] Q.base;
Q.base = NULL;
Q.front = Q.rear = 0;
}
}
int main() {
SeqQueue Q;
InitQueue(Q);
EnQueue(Q, 1);
EnQueue(Q, 2);
EnQueue(Q, 3);
int e;
DeQueue(Q, e);
cout << e << endl;
DestroyQueue(Q);
return 0;
}