下面函数使用快慢指针查找单链表的中间结点。横线处应填写( )。
struct Node {
int value;
Node *next;
};
Node *middle(Node *head) {
Node *slow = head;
Node *fast = head;
while (fast != nullptr && fast->next != nullptr) {
slow = slow->next;
______________________
}
return slow;
}
- A.
fast = fast->next; - B.
fast = fast->next->next; - C.
fast = slow->next; - D.
fast = head->next;