In the method of removing nodes, After completing this operation: prev.next = next
&& next?.previous = prev
it seems that the node has no more strong reference. At this time, the node should have been destroyed, but in the end why can ”return the node value“?
here is code in the resource file:
QueueChallenge → Sources → DoubleLinkedList.swift → remove function
public func remove(_ node: Node<T>) -> T {
let prev = node.previous
let next = node.next
if let prev = prev {
prev.next = next // 👈 here
} else {
head = next
}
next?.previous = prev // 👈 here
if next == nil {
tail = prev
}
node.previous = nil
node.next = nil
return node.value // 👈 here
}