您的位置:首页 > 编程语言 > Go语言

算法之旅,直奔<algorithm>之二十一 max

2013-12-22 11:27 399 查看

max(vs2010)


引言
这个是我学习总结<algorithm>的第二十一篇。这个也是目前来说最简单的一个函数了,对初学者来说都是so easy的。
作用
max的作用求出两个数的最大值。
原型
template <class T> const T& max (const T& a, const T& b) {
return (a<b)?b:a;     // or: return comp(a,b)?b:a; for version (2)
}

实验
                


代码
test.cpp
#include <iostream>     // std::cout
#include <algorithm>    // std::max

int main () {
std::cout << "max(1,2)==" << std::max(1,2) << '\n';
std::cout << "max(2,1)==" << std::max(2,1) << '\n';
std::cout << "max('a','z')==" << std::max('a','z') << '\n';
std::cout << "max(3.14,2.73)==" << std::max(3.14,2.73) << '\n';

system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  algorithm vs2010 c++