不用辅助变量交换数据?
我想请教一个问题:写一个函数 swap(int x,int y), 交换x,y的值,但是不能使用辅助变量
这个函数怎么写啊
#include<iostream>
using namespace std;
void swap(int &v1,int &v2)
{
v1 = v1^v2;
v2 = v1^v2;
v1 = v1^v2;
}
void main()
{
int a=3,b=5;
swap(a,b);
cout<<"a="<<a<<'\t'<<"b="<<b<<endl;
}