1.void swap(int &x, int &y){
int temp=x;
x=y;
y=temp;
}
2.void swap(int &x, int &y){
x=x+y;
y=x-y;
x=x-y;
}
3.void swap(int &x, int &y){
x=x-y;
y=x+y;
x=y-x;
}
4.void swap(int &x, int &y){
x=x^y;
y=x^y;
x=x^y;
}
四种变量交换swap方法
时间: 2024-12-27 16:53:17