2021/11/26
void swap(int* a, int* b)
{
int temp = *a;
*a = *b;
*b = temp;
}
#include<stdio.h>
main()
{
char a, b, c;
printf("please input three characters,system will sort them by ASC code size:\n");
scanf_s("%c %c %c", &a, 2, &b, 2, &c, 2);
if (a > b)
swap(&a, &b);
if (b > c)
swap(&b, &c);
if (a > c)
swap(&a, &c);
printf("the result is:%c %c %c\n", a, b, c);
}
这道题我在例题的专栏里提到了,那篇文章里的算法要低效无用的多,现在的解法要简洁的多,以后应该还有机会优化。
这篇博客展示了如何使用交换函数高效地对输入的三个字符进行升序排序。通过简化代码,提高了算法的效率。博主讨论了算法的改进,并指出未来可能的进一步优化。

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



