c++ 函数模板实现排序的程序

来源:百度知道 编辑:UC知道 时间:2024/06/01 19:24:13
好像有错误,请高手看看!
#include <iostream.h>

template <class T>
inline T max(T *a,T *b,T *c)
{
if(a>b)
{
int temp=a;
a=b;
b=temp;

if(b>c)

int temp=b;
b=c;
c=temp;

}
}

inline T max(int,int,int);

void mian()
{
int n1,n2,n3;
cin>>n1>>n2>>n3;
max(n1,n2,n3);
cout<<max(n1,n2,n3)<<endl;
}

不是好像,是问题大了。
函数严重错误!!

#include <iostream>
using namespace std;
template <class T>
void max(T m1,T m2,T m3){
T temp;
temp=m1;
if (m1>m2){
temp=m1;m1=m2;m2=temp;
}
if (m1>m3){
temp=m1;m1=m3;m3=temp;
}
if (m2>m3){
temp=m2;m2=m3;m3=temp;
}
cout<<m1<<","<<m2<<","<<m3;
}
int main(){
int a,b,c;
cin>>a>>b>>c;
max(a,b,c);
cout<<endl;
system("PAUSE");
}这段代码就应该没有问题了。

貌似没什么错啊~

cout<<a[i];
大哥,你的不是好像有错误,本来我是想在原题上改的,但放弃了。
你基础知识再加强下吧。连主函数都拼错了,逻辑也没用弄明白,对模板的基本概念也没搞懂,inline也不是狗皮膏药,怎么贴都没问题的。我做了一个简单的排序函数模板,供你参考吧。