Solution of reorder list problem