加文

希望是美好的……
随笔 - 0, 文章 - 209, 评论 - 0, 引用 - 0
数据加载中……

函数模板定制

#include <iostream>
#include <string>
using namespace std;
template<typename T>T min(T ii,T jj,T kk)
{
    T temp;
    if((ii<jj)&&(ii<kk))
        temp = ii;
    else if((jj<ii)&&(jj<kk))
        temp = jj;
    else  
        temp = kk;
    return temp ;
}
const char* min(const char* ch1,const char* ch2,const char* ch3)
{
    const char* temp;
    int result1 = strcmp(ch1,ch2);
    int result2 = strcmp(ch1,ch3);
    int result3 = strcmp(ch2,ch1);
    int result4 = strcmp(ch2,ch3);

    if((result1<0)&&(result2<0))
        temp = ch1;
    else if((result3<0)&&(result4<0))
        temp = ch2;
    else
        temp = ch3;
    return temp;
}
int main()
{
    cout<<min(100,20,30)<<endl;
    cout<<min(10.60,10.64,53.21)<<endl;
    cout<<min('c','a','C');
    string str1 = "Anderson";
    string str2 = "Wasoton";
    string str3 = "Smith";
    
    cout<<'\n'<<min(str1,str2,str3)<<endl;
    cout<<min("Anderson","Wasoton","Smith");
    getchar();
    return 0;

}

posted on 2012-02-11 23:33 加文 阅读(89) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理