- The function
copyNodes(returningCopyOf node: Node<Value>?)should return the node itself, notnilwhen copy is not performed. Otherwise, the node is not removed from the list. - The insertion function, should use
copyNodes(returningCopyOf node: Node<Value>?)instead of regularcopyNodes()for the same reason,removedoes. - This is trickier to correct, and I believe requires different approach to COW - when performing operations on the first node - we create additional reference to
head, which forces copy to be performed, even when data structure itself is not really copied.
A correction in the source code would be greatly appreciated.