A. [GESP]L5-202512-Q3636-S
[GESP]L5-202512-Q3636-S
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
对如下定义的循环单链表,横线处填写( )。
// 循环单链表的结点
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 << " ";
}
{{ select(1) }}
- A
- B
- C
- D
GESP 2025.12 C++ 五级 全真模拟赛
- 状态
- 已结束
- 规则
- OI
- 题目
- 27
- 开始于
- 2026-11-20 13:33
- 结束于
- 2026-11-25 13:33
- 持续时间
- 2 小时
- 主持人
- 参赛人数
- 0