Rearrange array in place