I am addressing an optimization problem involving a doubly linked list, where nodes are allocated within a contiguous memory block of fixed size $N$. Initially, the spatial locality of nodes in memory is not preserved, meaning that the next
pointers of nodes might refer to any other node within the block.
The objective is to reorder the nodes such that for each node $i$, its successor node $j$ in the list is also its immediate successor in memory (i.e., memory[i]
directly precedes memory[i + 1]
.
A trivial solution would involve traversing the linked list, storing the nodes in an auxiliary ordered container, and then copying them back into the memory block in order.
However, the goal is to reorder the nodes directly within the memory block, potentially using an auxiliary structure but performing the reordering through in-place swaps. Is such in-place reordering even feasible?