Why are shared_ptrs used here instead of unique_ptrs or raw pointers?
8. shared_ptrs in ListNode prototype
Hey Piper,
It is because for some of our problems we might have multiple ListNodes point to one ListNode, and in this situation, we cannot use unique_ptr.
From the design perspective of linked list, it makes sense as there is no rule about how many people can point to a list node. On the contrary, binary tree has such restriction where each node can be pointed by one node.
1 Like