宏定义在c++程序编译过程中,在宏替换过程中直接替换相关代码,效率会有很大的提升。
今天谈一下SWAP交换的几种编写方式:
#define SWAP(a,b) \
do{
int temp = a; \
a = b; \
b = temp; \
}while(false)
还有一种编写方式:
#define SWAP(a,b) (a=(a)+(b),b=(a)-(b),a=(a)-(b))
宏定义在c++程序编译过程中,在宏替换过程中直接替换相关代码,效率会有很大的提升。
今天谈一下SWAP交换的几种编写方式:
#define SWAP(a,b) \
do{
int temp = a; \
a = b; \
b = temp; \
}while(false)
还有一种编写方式:
#define SWAP(a,b) (a=(a)+(b),b=(a)-(b),a=(a)-(b))