下面 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;