使用数组或动态分配的内存实现。
int queue[100];
int head = 0, tail = 0;
void enqueue(int item) {
if ((tail + 1) % 100 == head) return; // 队列满
queue[tail] = item;
tail = (tail + 1) % 100;
}
int dequeue() {
if (head == tail) return 0; // 队列空
int item = queue[head];
head = (head + 1) % 100;
return item;
}

被折叠的 条评论
为什么被折叠?



