#include<stdio.h>
void exchange(int *q1,int *q2,int *q3);
void swap(int *t1,int *t2)
{
if(*t1<*t2)
{
int temp;
temp=*t1;
*t1=*t2;
*t2=temp;
}
}
int main()
{
int a,b,c,*p1,*p2,*p3;
scanf("%d%d%d\n",&a,&b,&c);
p1=&a;
p2=&b;
p3=&c;
exchange(p1,p2,p3);
printf("%d %d %d",a,b,c);
return 0;
}
void exchange(int *q1,int *q2,int *q3)
{
swap(q1,q2);
swap(q1,q3);
swap(q2,q3);
}
图片:
本文展示了一个使用C语言编写的简单程序,该程序通过指针实现三个整数的交换排序。采用递归定义的方式,先进行两两比较并交换,最终达到排序效果。文章中的代码示例清晰地说明了这一过程。
2863

被折叠的 条评论
为什么被折叠?



