swap-with-next function