首页 / 客观题库

80542 - 线性表20

基础数据结构

题目(材料题)

下面C++代码实现双向链表。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

// 节点结构体

struct Node {

    int data;

    Node* prev;

    Node* next;

};

// 双向链表结构体

struct DoubleLink {

    Node* head;

    Node* tail;

    int size;

    DoubleLink() {

       head = nullptr;

       tail = nullptr;

       size = 0;

    }

    ~DoubleLink() {

       Node* curr = head;

       while (curr) {

           Node* next = curr->next;

           delete curr;

           curr = next;

       }

    }

    // 判断链表是否为空

    bool is_empty() const {

       _______________________

    }

    void append(int data) {

       Node* newNode = new Node{ data, nullptr, nullptr };

       if (is_empty()) {

          head = tail = newNode;

        }

        else {

         _______________________

        }

       ++size;

    }

};

||
( 单选 )

函数 is_empty() 判断链表是否为空,如链表为空返回 true ,否则返回 false 。横线处不能填写( )。

A return head == nullptr;

B return head == nullptr;

C return head.data == 0;

D return head.data == 0;

( 单选 )

填入相应代码完善 append() ,用于在双向链表尾部增加新节点,横线上应填写( )。

A tail->next = newNode;

B newNode->prev = tail; tail = newNode;

C tail = newNode; newNode->prev = tail; tail->next = newNode;

D tail->next = newNode; newNode->prev = tail; tail = newNode;

意见反馈

    最多上传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