交换两个数
int temp;
int n=3,m=8;
temp = n;
n = m;
m = temp;
n = 3, m = 8;
n = n + m;//3+8=11
m = n - m;//11-8=3
n = n - m;//11-3=8
n = n ^ m;
m = n ^ m; //(n ^ m) ^ m;
n = n ^ m; //(n ^ m) ^ n;
交换两个数
int temp;
int n=3,m=8;
temp = n;
n = m;
m = temp;
n = 3, m = 8;
n = n + m;//3+8=11
m = n - m;//11-8=3
n = n - m;//11-3=8
n = n ^ m;
m = n ^ m; //(n ^ m) ^ m;
n = n ^ m; //(n ^ m) ^ n;
本文标题:置换两个数
本文链接:https://www.haomeiwen.com/subject/deoypxtx.html
网友评论