#include <stdio.h>
#include <stdbool.h>
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);
}