首页 / 客观题库

Q80545 - 线性表23

基础数据结构

题目( 单选题 )

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

// 链表结点

template <typename T>

struct ListNode {

    T data;

    ListNode* prev;

    ListNode* next;

    // 构造函数

    explicit ListNode(const T& val = T())

       : data(val), prev(nullptr), next(nullptr) {}

};

struct LinkedList {

    ListNode<T>* head;

    ListNode<T>* tail;

};

void InitLinkedList(LinkedList* list) {

    list->head = new ListNode<T>;

    list->tail = new ListNode<T>;

    ________________________________ // 在此处填入代码

};

A

list->head->prev = list->head;

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

B

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

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

C

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

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

D

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

list->tail->next = nullptr;

意见反馈

    最多上传3张图片,格式为JPG、PNG、JPEG,单张不超过5MB

    注册

    发送验证码

    密码必须包含数字、字母和特殊字符

    找回密码

    发送验证码

    密码必须包含数字、字母和特殊字符

    运行 ID:67149

    • 测试点1:Accepted
    • 用时:0 ms
    • 内存:288 kb
    • 测试点2:Accepted
    • 用时:0 ms
    • 内存:288 kb
    输入
    203
    输出
    203

    test

    测评信息

    错误.in文件下载

    错误.out文件下载

    运行 ID:67149

    2019-01-24 15:06:36