Each tile has a hidden value. Sort them by it. That's all.
Choose two tiles. If left > right, they will be swaped.