Errata Chapter 7

Just FYI not a critical error:

The solution code for the deserialization on the first implementation is wrong. The book has the final implementation after the optimization. I realized this as I read on but wasn’t apparent why I was getting the wrong console output compared to the book.

Book Implementation: fun deserialize(list: MutableList<T?>): BinaryNode<T?>? { val rootValue = list.removeAt(list.size - 1) ?: return null

correct Implementation:fun deserialize(list: MutableList<T?>): BinaryNode<T?>? { val rootValue = list.removeAt(0) ?: return null

also a small error on the deserializationOptimized method’s return type:

Book Implementation: fun deserializeOptimized(list: MutableList<T?>): BinaryNode<T>?

correct Implementation:fun deserializeOptimized(list: MutableList<T?>): BinaryNode<T?>?

1 Like