3 ms·
Ugh, linked lists fuck everything up. It’s never the right data structure. Use a vector!
by earthboundkid 7y ago
Ugh, linked lists fuck everything up. It’s never the right data structure. Use a vector!
- anarazel 7y agoThat's only true if you actually need to access more than a few elements at once. And if you never need to insert/delete to/from anywhere but the end.
- earthboundkid 7y agoEven if you need middle inserts but not a B-tree (weird), it’s still better to use a vector in most cases. Time to find the insertion point will dominate.
- giornogiovanna 7y agoThe two main cases when linked lists are better are (a) when you want to guarantee a low cost per insert, since vector insertion is only O(1) amortized, and (b) when you want to insert in the middle, but somehow found that middle without scanning the list. Anyway, in this case, I guess they're using a free list because (1) it's simpler since you don't need an external collection keeping a list of unused stuff, and (2) reason (a) above.