mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
A bug fix.
This commit is contained in:
@ -66,11 +66,12 @@ void push(ArrayQueue *queue, int num) {
|
||||
}
|
||||
|
||||
/* 出队 */
|
||||
void pop(ArrayQueue *queue) {
|
||||
int pop(ArrayQueue *queue) {
|
||||
int num = peek(queue);
|
||||
// 队首指针向后移动一位,若越过尾部则返回到数组头部
|
||||
queue->front = (queue->front + 1) % queue->queCapacity;
|
||||
queue->queSize--;
|
||||
return num;
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
@ -93,7 +94,7 @@ int main() {
|
||||
printf("队首元素 peek = %d\r\n", peekNum);
|
||||
|
||||
/* 元素出队 */
|
||||
pop(queue);
|
||||
peekNum = pop(queue);
|
||||
printf("出队元素 pop = %d ,出队后 queue = ", peekNum);
|
||||
printArray(queue->nums, queue->queSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user