算法与数据结构之交换(SWAP)排序

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 void swap(int x,int y);
 5 void swap_p(int *px,int *py);
 6 #define swap_m(x,y,t) ((t)=(x),(x=(y),(y)=(t)))//宏函数
 7 int main(void)
 8 {
 9     int a,b,temp;
10     a=1;
11     b=10;
12     printf("a=%d,b=%d
",a,b);
13     //swap_p(&a,&b);//指针实际上是地址
14     swap_m(a,b,temp);
15     printf("a=%d,b=%d
",a,b);
16     system("pause");
17 }
18 
19 void swap(int x,int y)//该方法无法实现
20 {
21     int temp;
22     temp=x;
23     x=y;
24     y=temp;
25 }
26 
27 void swap_p(int *px,int *py)//指针实现,对传入参数的内存地址进行操作
28 {
29     int temp;
30     temp=*px;
31     *px=*py;
32     *py=temp;
33 }

原文地址:https://www.cnblogs.com/haciont/p/4796968.html