0
LHofman
14d

When is it a good idea to use linked lists?

In my pet project, I want to have a list of items with an index. The index of an item should be updateable, and the index of the other items should adjust.

A linked list would make it very easy to adjust the order since you just need to update the "next" node of 2 items, but I think this would make getting the index of items more troublesome.

What is the preferred way to do something like this, am I just overthinking it, and would updating all the indices of the items not be such a big job?

The project uses React and mongo (express-mongoose) btw, if that's important.

Comments
  • 1
    Basically, you don't use linked lists. Their only advantage is O(1) insertion/deletion, but the lookup is already O(N) anyway. Also, they tend to trash CPU caches and prediction. Actually, vector is faster.

    Stroustrup on why you should avoid linked lists: https://youtube.com/watch/...
  • 1
    @Fast-Nop

    Thank You .... Sir
  • 0
    Keep It Simple, Stupid 😜 (rule of KISS)
  • 1
    Pretty sure you'd just use a vector like @Fast-Nop said.

    Although I just had a dumb thought, aren't linked lists just unary trees?
Add Comment