3种交换变量值的方法

来源:互联网 发布:程序员节活动策划 编辑:程序博客网 时间:2024/04/28 19:59
//中间变量法void swap1(int& a,int& b){    int temp=a;    a=b;    b=temp;}//相互加减法void swap2(int& a,int& b){    a=a+b;//可能会溢出    b=a-b;    a=a-b;}//异或法void swap3(int& a,int& b){    a^=b;    b^=a;    a^=b;}
转自http://www.cppblog.com/cxiaojia/archive/2012/03/07/167347.html
0 0