如下定义的C++循环单链表printList函数的空缺处应填写的正确代码是?

zi816523 单选题 共 个子题
// 循环单链表的结点
struct Node {
    int data;      // 数据域
    Node* next;    // 指针域
    Node(int d) : data(d), next(nullptr) {}
};
// 创建一个只有一个结点的循环单链表
Node* createList(int value) {
    Node* head = new Node(value);
    head->next = head;
    return head;
}
// 在循环单链表尾部插入新结点
void insertTail(Node* head, int value) {
    Node* p = head;
    while (p->next != head) {
        p = p->next;
    }
    Node* node = new Node(value);
    node->next = head;
    p->next = node;
}
// 遍历并输出循环单链表
void printList(Node* head) {
    if (head == nullptr) return;
    Node* p = head;
    _______________ // 在此处填入代码
    cout << endl;
}
A
while (p != nullptr){    cout << p->data << " ";    p = p->next;}
B
while (p->next != nullptr){    cout << p->data << " ";    p = p->next;}
C
do {    cout << p->data << " ";    p = p->next;} while (p != head);
D
for(; p; p=p->next){    cout << p->data << " ";}
正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧