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\n",a,b);
13     //swap_p(&a,&b);//指针实际上是地址
14     swap_m(a,b,temp);
15     printf("a=%d,b=%d\n",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 }

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

相关文章:

  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2022-02-01
  • 2021-08-22
  • 2021-09-26
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2020-11-07
相关资源
相似解决方案