I'm curious as to what is the correct way of deleting all nodes in a doubly linked list.
Here's my linked list structure:
type ListNode struct {
Data branch
Next *ListNode
Prev *ListNode
}
type doublyLinkedList struct {
Head *ListNode
Tail *ListNode
Size int
}
Will it work if I just point the Head & Tail nodes to Nil?
func deleteAllNodes(dl *doublyLinkedList) {
dl.Head = nil
dl.Tail = nil
dl.Size = 0
}
If so, what happens to all the nodes? Does it get garbage collected?