Every pop moves the whole list unless you get fancy an implement it as an array with head and tail pointers and grow logic.
If you keep a tail pointer inserts are likewise O(1).
You rarely traverse them.
Every pop moves the whole list unless you get fancy an implement it as an array with head and tail pointers and grow logic.
If you keep a tail pointer inserts are likewise O(1).
You rarely traverse them.
(The best optimization you could do in such a case would be to allocate multiple slots per pointer, to amortize the malloc/free time. Then you'd want to run benchmarks to tell what the optimal amount of slots would be. If a vector is optimal, as I strongly expect it would be, the answer would come out to be, "all of them".)
Modern processors move chunks of RAM around really quickly. They're really optimized for it. It is one of the major things I'm referring to when I say our systems have been optimized for C. I often wonder about what an architecture designed in a world where linked lists were dominant would look like. However, it is certainly not this world.