//编写模板函数sort,功能是:对三个形参a, b, c按照从大到小排序。(10分)
#include<iostream>
#include<string>
using namespace std;
template<typename T> //模版声明
void sort( T &a, T &b, T &c )
{
if(a<b){
T temp=a;
a=b;
b=temp;
}if(a<c){
T temp = a;
a = c;
c=temp;
}
if(b<c){
T temp = b;
b =c;
c=temp;
}
}
int main () {
int i1,i2,i3;
cin>>i1>>i2>>i3;
sort(i1,i2,i3);
cout<<i1<<i2<<i3<<endl;
double d1,d2,d3;
cin>>d1>>d2>>d3;
sort(d1,d2,d3);
cout<<d1<<d2<<d3<<endl;
string s1,s2,s3;
cin>>s1>>s2>>s3;
sort(s1,s2,s3);
cout<<s1<<s2<<s3<<endl;
return 0;
}
问题四:编写模板函数sort,功能是:对三个形参a, b, c按照从大到小排序。
最新推荐文章于 2024-03-04 21:01:23 发布