编辑代码

#include <stdio.h>
#include <stdbool.h>

//1.数组实现队列
int Query[10];
int front = -1;
int rear = -1;
int length = sizeof(Query) / sizeof(int);

//判断队列是否已满
bool isFull() {
    //使用循环数组,充分利用数组中的内存
    int temp = (rear + 1) % length;
    if(temp == front) {
        return true;
    }
    return false;
}
//查看队列中的第一个元素
int Front() {
    //判断队列是否为空
    if (front == -1 || rear == -1) {
        printf("队列为空,查看失败!\n");
        return NULL;
    }
    return Query[front];
}
//入队操作
void Enquery(int x) {
    //判断队列是否为空
    if (front == -1 || rear == -1) {
        front = 0;
        rear = 0;
        Query[rear] = x;
        return;
    }
    else if (isFull()) {
        printf("队列已满,插入失败!\n");
        return;
    }
    rear = (rear + 1) % length;
    Query[rear] = x;

    return;
}
//出队操作
void Dequery() {
    //判断队列是否为空
    if (front == -1 || rear == -1) {
        printf("队列为空,删除失败!\n");
        return;
    }
    else if (front == rear) {
        front = -1;
        rear = -1;
    }
    front = (front + 1) % length;
}
//遍历打印队列
void Print() {
    //判断队列是否为空
    if (front == -1 || rear == -1) {
        printf("队列为空,遍历失败!\n");
        return;
    }
    int i = front;
    while (i != rear) {
        printf("%d ", Query[i]);
        i = (i + 1) % length;
    }

    printf("%d \n",Query[rear]);
    return;
}

int main () {
    Enquery(0);
    Enquery(1);
    Enquery(2);
    Enquery(3);
    Enquery(4);
    Enquery(5);
    Enquery(6);
    Enquery(7);
    Enquery(8);
    Enquery(9);
    Print();
    Enquery(9);
    Enquery(9);

}