\begin{algorithm} \caption{Compactify List} \begin{algorithmic} \INPUT doubly linked list $L$ and $F$ stored in multiple arrays $free$, $prev$ and $next$ \PROCEDURE{SwapObject}{$i, j$} \STATE \CALL{Swap}{$next[prev[i]], next[prev[j]]$} \STATE \CALL{Swap}{$prev[next[i]], prev[next[j]]$} \STATE \CALL{Swap}{$prev[i], prev[j]$} \STATE \CALL{Swap}{$next[i], next[j]$} \STATE \CALL{Swap}{$key[i], key[j]$} \ENDPROCEDURE \STATE \STATE $x = L.head$ \STATE $i = 1$ \WHILE{$x \ne NIL$} \STATE \CALL{SwapObject}{$i, x$} \IF {$F.head = i$} \STATE $F.head = x$ \ENDIF \STATE $x = next[i]$ \STATE $i = i + 1$ \ENDWHILE \STATE $L.head = 1$ \end{algorithmic} \end{algorithm}