Re:The true cost of linked lists
by marginalia_nu on Monday June 06, 2022 @09:28AM
(#31640177)
> If you remove a node in the list now you have to rewrite all the values in the links array.
You actually don't. You can just keep two lists within the same structure, one for occupied nodes and one for free nodes, and just move deletions to the head of the free nodes list.
Example List:
Data: [ a, 0, c, d, e ]
Links: [ 2, -1, 3, 4, -1 ]
Head of occupied nodes: 0
Head of free nodes: 1
You actually don't. You can just keep two lists within the same structure, one for occupied nodes and one for free nodes, and just move deletions to the head of the free nodes list.
Example List:
Link shape: To Delete C: This changes the data such: New shape: