2

sorry if this been asked already...

Why and when Should I use linked lists over vectors? I just don't like all those pointer overheads...

From my knowledge: vector is faster, more compact because there's no extra pointers, and is easier to implement; also I think that linked lists do not exploit the principle of spatial locality because nodes are in totally random memory locations so your code becomes slower... so when you are using linked lists you are increasing your cache misses which you don't want to do...

Of course the advantage of lists is that you can avoid overflows with dynamic memory allocation...

In summation, my question is: where should you use, if ever, linked lists over vectors? which data struct do you prefer more?

Mikhail
  • 8,692
  • 8
  • 56
  • 82
lychee
  • 1,771
  • 3
  • 21
  • 31

1 Answers1

1

Linked Lists are for situations where you want to insert or remove an item without shifting or insert/push or pop item in constant time and when you don't know the number of elements and maybe don't need a random access. for more information see this .

Community
  • 1
  • 1
Amen
  • 1,524
  • 5
  • 22
  • 41