下面代码遍历并输出一个循环单链表,其中 head 指向链表的第一个节点,横线处应填入的是( )。

au100816 单选题 共 个子题
struct Node {
    int val;
    Node* next;
};

void printList(Node* head) {
    if (head == nullptr) return;
    Node* p = head;
    _______________________ // 在此处填入代码
    cout << endl;
}
A
while (p != nullptr) {
cout << p->val << " ";
p = p->next;
}
B
while (p->next != nullptr) {
cout << p->val << " ";
p = p->next;
}
C
do {
cout << p->val << " ";
p = p->next;
} while (p != head);
D
for (; p; p = p->next) {
cout << p->val << " ";
}
正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧