方法1 : 加减法
a = a + b; b = a - b; a = a - b;
例子:a = 5 ; b = 3;
a = a + b = 5 + 3 = 8; b = a - b = 8 - 3 = 5; a = a - b = 8 - 5 = 3;
方法2: 异或法
a = a ^ b; b = a ^ b; a = a ^ b;
例子:a = 7 ; b = 9;
a = a ^ b = 0111 ^ 1001 = 1110;
b = a ^ b = 1110 ^ 1001 = 0111 = 7;
a = a ^ b = 1110 ^ 0111 = 1001 = 9;