#define swap(x,y) {int temp=x;x=y;y=temp;}
//换行写法
#define swap(x, y)\
int temp = x;\
x = y;\
y = temp;


#define swap(x,y)  {x= x+y;y=x-y;x=x-y;}
//换行写法
#define swap(x,y)\
x=x+y;\
y=x-y;\

x=x-y;\


通过按位异或运算,可以实现两个值的交换,而不必使用临时变量

void swap(int &a,int &b)
{
    a=a^b;
    b=a^b;
    a=a^b;

}


相关文章:

  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
相关资源
相似解决方案