只想知道这个删除链表的实现是否有任何缺陷/不一致/内存泄漏:
// Function to delete the entire linked list
void deleteList(Node** head) {
Node* current = *head;
Node* next;
while (current != 0) {
next = current->next;
delete current;
current = next;
}
*head = 0;
}
编辑:
struct Node {
int data;
Node* next;
Node(int data) : data(data){}
};