#include<iostream>
#include<string>
using namespace std;
template<typename T> //模版声明
void sort( T a,T b,T c)
{ T s[3],t;
int n=3;
s[0]=a;
s[1]=b;
s[2]=c;
for(int i=0;i<n-1;i++){
for(int j=0;j<n-i-1;j++){
if(s[i]<s[i+1])
{
t=s[i+1];
s[i+1]=s[i];
s[i]=t;
}
}
}
cout<<s[0]<<" "<<s[1]<<" "<<s[2]<<" "<<endl;
}
int main () {
int i1,i2,i3;
cout<<"请输入三个整数";
cin>>i1>>i2>>i3;
sort(i1,i2,i3);
cout<<i1<<" "<<i2<<" "<<i3<<" "<<endl;
double d1,d2,d3;
cout<<"请输入三个小数";
cin>>d1>>d2>>d3;
sort(d1,d2,d3);
cout<<d1<<" "<<d2<<" "<<d3<<" "<<endl;
string s1,s2,s3;
cout<<"请输入三个字符串";
cin>>s1>>s2>>s3;
sort(s1,s2,s3);
cout<<s1<<" "<<s2<<" "<<s3<<" "<<endl;
return 0;
}
运行结果: