题库 C++/C语言题库 题目列表 假设双向循环链表包含头尾哨兵结点(不存储实际内容),...
单选题

假设双向循环链表包含头尾哨兵结点(不存储实际内容),分别为headtail,链表中每个结点有两个指针域prevnext,分别指向该结点的前驱及后继结点。下面代码实现了一个空的双向循环链表,横线上应填的最佳代码是( )

1 // 链表结点
2 template <typename T> 
3 struct ListNode { 
4  T data; 
5  ListNode* prev; 
6  ListNode* next; 
7
8  // 构造函数 
9  explicit ListNode(const T& val = T()) 
10   : data(val), prev(nullptr), next(nullptr) {} 
11 }; 
12
13 struct LinkedList { 
14  ListNode<T>* head; 
15  ListNode<T>* tail; 
16 }; 
17
18 void InitLinkedList(LinkedList* list) { 
19  list->head = new ListNode<T>; 
20  list->tail = new ListNode<T>; 
21  ________________________________ // 在此处填入代码 
22 };


A.

1 list->head->prev = list->head; 
2 list->tail->prev = list->head;

B.

1 list->head->next = list->tail; 
2 list->tail->prev = list->head;

C.

1 list->head->next = list->tail; 
2 list->tail->next = list->head;

D.

1 list->head->next = list->tail; 
2 list->tail->next = nullptr;

题目信息
2025年 五级 选择题
-
正确率
0
评论
6
点击