reorder

perm - permutation with the length of current nodes. The permutation
lists the new positions of the original nodes, that is, for nodes
[A,B,C,D] and permutation [0,3,1,2], the final
order would be [A,C,D,B].