函数 hasCycle 采用Floyd快慢指针法判断一个单链表中是否存在环,链表的头节点为 head ,即用两个指针在链表上前进: slow 每次走 1 步, fast 每次走 2 步,若存在环, fast 终会追上 slow (相遇);若无环,fast 会先到达 nullptr,则横线上应填写( )。

A. slow = slow->next; fast = fast->next->next;
B. slow = fast->next; fast = slow->next->next;
C. slow = slow->next; fast = slow->next->next;
D. slow = fast->next; fast = fast->next->next;
正确答案:A
试卷来源:202509 CCF-GESP编程能力等级认证C++五级真题