假设 head != nullptr ,下面是实现单向循环链表在头节点后插入新节点的代码,横线处应填入( )。 struct Node { int val; Node* next; }; void insertAfterHead(Node* head, int x) { Node* newNode = new Node; newNode->val = x; --------------------// 填空位置 }
A:newNode->next = head;head->next = newNode;
B:newNode->next = head->next;head->next = newNode;
C:head->next = newNode;newNode->next = head->next;
D:newNode->next = head->next;head = newNode;
正确答案:B
试卷来源:202606 CCF-GESP编程能力等级认证C++五级真题