下 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. return head == nullptr;
- B. return tail == nullptr;
- C. return head.data == 0;
- D. return size == 0;
正确答案:C