1.借助中间量交换
int x = 10;
int y = 20;
int temp = x;
x = y;
int x = 10;
int y = 20;
int temp = x;
x = y;
y = temp;
2.数值相加减交换
int x = 10;
int y = 20;
x = x + y;
y = x - y;
x = x - y;
3.异或运算交换
int x = 10;
int y = 20;
x = x ^ y;
y = x ^ y;
x = x ^ y;

2863

被折叠的 条评论
为什么被折叠?



