请问这个问题如何解决

问题遇到的现象和发生背景

给定一个初始为空的队(队存储空间长度为10)和一系列进队、出队操作,请编写程序输出经过这些操作后队中的元素。队中元素值均为整数。(采用循环队列完成,禁用一个空间方法)

输入格式:
输入第1行为1个正整数n,表示操作个数;

第2行为给出的n个整数,非0元素表示进队,且此非0值即为进队元素,0元素表示出队。

输出格式:
第一行按出队顺序输出所有出队元素,以一个空格隔开;如果队空时做出队操作会输出"EMPTY",如果队满时做进队操作会输出"FULL"。

第二行中输出队中所有元素,以一个空格隔开。

末尾均有一个空格。

问题相关代码,请勿粘贴截图
#include<iostream>
using namespace std;
#define ERROR 0
#define OK 1
#define MAXQSIZE 10
typedef int QElemtype;
typedef int status;
typedef struct
{
    QElemtype *base;
    int rear;
    int front;
}SqQueue;
status InitQueue(SqQueue &Q)
{
    Q.base = new QElemtype[MAXQSIZE];
    if (!Q.base)
        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 OK;
    else
    {
        return ERROR;
    }
}
status IsEmpty(SqQueue &Q)
{
    if (Q.front == Q.rear)
        return OK;
    else
        return ERROR;
}
status IsFull(SqQueue &Q)
{
    if ((Q.rear + 1) % MAXQSIZE == Q.front)
        return OK;
    else
        return ERROR;
}
status DestroyQueue(SqQueue &Q)
{
    free(Q.base);
    Q.base = 0;
    Q.front = 0;
    if (Q.base == 0)
    {
        return OK;
    }
    else
    {
        return ERROR;
    }
}
int main()
{
    SqQueue Q;
    int n, i, op, e;
    InitQueue(Q);
    printf("请输入操作次数");
    cin >> n;
    printf("请输入操作:");
    for (i = 0; i < n; i++)
    {
        cin >> op;
        if (op) 
        {
            if (IsFull(Q))
                cout << "FULL";
            else
                EnQueue(Q, op);
        }
        else
        {
            if (IsEmpty)
                cout << "EMPTY";
            else
            {
                DeQueue(Q,e);
                cout << e << " ";
            }
        }
    }
    cout.put('\n');
    while (!IsEmpty(Q))
    {
        DeQueue(Q, e);
        cout << e << " ";
    }
    cout << endl;
    DestroyQueue(Q);
    return 0;
}

运行结果及报错内容

img

我的解答思路和尝试过的方法

不知道如何解决

我想要达到的结果

程序可以正常运行

(1)初始化时,没有初始化rear和front
(2)出队逻辑写错了
修改后运行结果:

img

代码修改如下:

#include<iostream>
using namespace std;
#define ERROR 0
#define OK 1
#define MAXQSIZE 10
typedef int QElemtype;
typedef int status;
typedef struct
{
    QElemtype *base;
    int rear;
    int front;
}SqQueue;
status InitQueue(SqQueue &Q)
{
    Q.base = new QElemtype[MAXQSIZE];
    Q.rear = 0;
    Q.front = 0;
    if (!Q.base)
        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;
    else
    {
        Q.rear -= 1;
        e = Q.base[Q.rear];
        return OK;
    }
}
status IsEmpty(SqQueue &Q)
{
    if (Q.front == Q.rear)
        return OK;
    else
        return ERROR;
}
status IsFull(SqQueue &Q)
{
    if ((Q.rear + 1) % MAXQSIZE == Q.front)
        return OK;
    else
        return ERROR;
}
status DestroyQueue(SqQueue &Q)
{
    free(Q.base);
    Q.base = 0;
    Q.front = 0;
    if (Q.base == 0)
    {
        return OK;
    }
    else
    {
        return ERROR;
    }
}
int main()
{
    SqQueue Q;
    int n, i, op, e;
    InitQueue(Q);
    printf("请输入操作次数");
    cin >> n;
    printf("请输入操作:");
    for (i = 0; i < n; i++)
    {
        cin >> op;
        if (op) 
        {
            if (IsFull(Q))
                cout << "FULL";
            else
                EnQueue(Q, op);
        }
        else
        {
            if (IsEmpty(Q))
                cout << "EMPTY";
            else
            {
                DeQueue(Q,e);
                cout << e << " ";
            }
        }
    }
    cout.put('\n');
    while (!IsEmpty(Q))
    {
        DeQueue(Q, e);
        cout << e << " ";
    }
    cout << endl;
    DestroyQueue(Q);
    return 0;
}