函数模板 3 个数排序,3 中类型 int char double
#include <stdio.h>#include <stdlib.h>
template <typename T>
void sort(T x,T y,T z,T a)
{
if(x>y){a=x;x=y;y=a;}
if(y>z){a=y;y=z;z=a;}
if(x>z){a=x;x=z;z=a;}
}
int main()
{
int a,b,c,x;
char d, e, f,y;
double h,i,j,z;
scanf("%d %d %d",&a,&b,&c);
fflush(stdin);
scanf("%c%c%c",&d,&e,&f);
fflush(stdin);
scanf("%lf %lf %lf",&h,&i,&j);
sort(a,b,c,x);
printf("%d %d %d\n",a,b,c);
sort(d,e,f,y);
printf("%c %c %c\n",d,e,f);
sort(h,i,j,z);
printf("%lf %lf %lf\n",h,i,j);
return 0;
}