#include<iostream> 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) { ; if (!Q.base) exit(OVERFLOW); ; return OK; } Status EnQueue(SqQueue &Q, QElemType e) { if ( ) return ERROR; Q.base[Q.rear] = e; ; return OK; } Status DeQueue(SqQueue &Q, QElemType &e) { if ( ) return ERROR; e = Q.base[Q.front]; ; return OK; } int main() { SqQueue Q; int n, i; char c; InitQueue(Q); cin >> n; for(i=0;i<n;i++){ cin >> c; EnQueue(Q,c); } for(i=0;i<n;i++){ DeQueue(Q,c); cout << c << " "; } return 0; } 补全这段代码
时间: 2024-02-14 13:15:14 浏览: 37
为了让代码能够正常运行,需要在代码中填充一些缺失的部分。下面是完整的代码:
```c++
#include<iostream>
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.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 DeQueue(SqQueue &Q, QElemType &e) {
if (Q.front == Q.rear)
return ERROR;
e = Q.base[Q.front];
Q.front = (Q.front + 1) % MAXQSIZE;
return OK;
}
int main() {
SqQueue Q;
int n, i;
char c;
InitQueue(Q);
cin >> n;
for(i=0;i<n;i++){
cin >> c;
EnQueue(Q,c);
}
for(i=0;i<n;i++){
DeQueue(Q,c);
cout << c << " ";
}
return 0;
}
```
这段代码实现了一个基于循环队列的队列,并且能够读入一串字符,将其入队,并依次出队输出。