swap1 and swap2, to count the number of swaps needed for the two cases.flag1 and flag2, to indicate if the conditions can be satisfied for the two cases.swap1 if a swap is needed and possible.flag1 to 0 and break out of the loop.swap2 to 1.swap2 if needed.flag2 to 0 and break out of the loop.swap1 and swap2.