The book mentions the following at the very end of Chapter 6:
The unidirectional nature of the linked list means that head-first insertions can ignore the “COW tax”!
However, I believe this also applies to pop()
operations as I’ve tested it by removing the copyNodes()
from the pop()
function and this was the result:
example(of: "non COW pop") {
var list = LinkedList<Int>()
list.push(3)
list.push(2)
list.push(1)
var list2 = list
list.pop()
print(list)
print(list2)
}
// Console
---Example of non COW pop---
[ 2 ] --> [ 3 ]
[ 1 ] --> [ 2 ] --> [ 3 ]