I have seen many implementations of linked list adding at head then updating the head reference or not modifying the head reference and adding at the tail updating it each time. Is there an obvious benefit of one vs the other? Which one is the preferred way of implementation?
Share
There’s no benefit at all. In fact, the only thing that makes the head the head and the tail the tail is that we call one the head and one the tail. You could replace head with tail, and tail with head, and you’d have the same exact list, except it would be “backwards.” (This does assume a doubly linked list…)
It’s kinda like matter and antimatter…