← Back to context

Comment by reificator

5 years ago

> If I grow by doubling the size (seems common)

True. Then it comes down to the size of your data vs the size of your pointers.

> What would you imagine the cases where LinkedList is still a valid data structure?

Compared to an array? When the array doesn't have the behavior that you need.

For instance, if you need to keep a stable reference to a particular element in a list, even while that list is being inserted into, then an array is not going to cut it. The linked list handles this case with ease.

That's not to say you can't write a wrapper for the array that does the right thing, probably for cheaper. But out of the box the linked list can do things that the array cannot and if you rely on them, then use the right tool for the job.