Help me in solving SWAPNUM31 problem

can anyone explain me how sorting took place in this question