With tmp varible:
inline void swap(int *a,int *b ){
int tmp=0;
tmp=*a;
*a=*b;
*b=tmp;
return;
}
Without tmp varible:
inline void swap(int *a,int *b ){
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
return;
}
reference:
http://www.velocityreviews.com/forums/t283891-swap-two-integers-without-using-a-tmp-variable.html
沒有留言:
張貼留言