Today I looked at my STL options well. Then I thought of something.
The linked list (std :: list) seems to be limited to limited use. Namely, it only really seems useful if
The order of the elements in my container matters, and
I need to erase or paste elements in the middle.
That is, if I just want a lot of data and don't care about its order, I better use std :: set (balanced tree) if I want to search for O (log n) or std :: unordered_map (hash map) if I I want to expect the expected search O (1) or std :: vector (adjacent array) for better locality of the link or std :: deque (double-ended queue) if I need to insert front and back.
OTOH, if the order matters, I better use std :: vector for better link locality and less overhead, or std :: deque if you need to resize.
So am I missing something? Or is the linked list just not that good? Except for the middle insert / erase, why does anyone want to use it?
source
share