reorder list with o(n)time