‹ 上一题 下一题 ›

g5-04350. GESP-5级-2025-06-单选-第02题 未做

1000 ms 256 MB 测试点 ? GESPGESP-52025-06单选客观题5级·链表链表

下面 C++ 代码实现双向链表。函数 is_empty() 判断链表是否为空,如果链表为空返回 true,否则返回 false。横线处不能填写( )。

// 节点结构体
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 {
        ____________
    }
};
  • A. ```cpp
    return head == nullptr;
- **B.** ```cpp
return tail == nullptr;
  • C. ```cpp
    return head.data == 0;
- **D.** ```cpp
return size == 0;
未选择
输入
输出

            
答案