Skip to content

Commit c2eb1db

Browse files
authored
Fix confusion between queSize and rear pointer in ArrayQueue implementation (#1851)
- `queSize` represents the queue's size, not the rear pointer position. - In `pop`, `queSize--` decreases the size, not the rear pointer. - The rear pointer is calculated using modulo (`%`) with the `front` and `queSize` to avoid confusion. Co-authored-by: Chance Luo <247349913+chanceluo1618-bot@users.noreply.github.com>
1 parent 6251b8e commit c2eb1db

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

codes/c/chapter_stack_and_queue/array_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
typedef struct {
1111
int *nums; // 用于存储队列元素的数组
1212
int front; // 队首指针,指向队首元素
13-
int queSize; // 尾指针,指向队尾 + 1
13+
int queSize; // 当前队列的元素数量
1414
int queCapacity; // 队列容量
1515
} ArrayQueue;
1616

0 commit comments

Comments
 (0)