赞
踩
(1)C = max(A, B);返回队列中的最大值。
#define max(a,b) (((a) > (b)) ? (a) : (b))
(1)C = min(A, B);返回队列中的最小值。
minmax()函数是算法标头的库函数,用于查找最小和最大值,它接受两个值并返回一对最小和最大值,该对中的第一个元素包含最小值,并且该对中的第二个元素包含最大值。
以数据对的形式(pair)返回队列中的最大值和最小值
注意:要使用minmax()函数 ,包括<algorithm>头文件,或者简单地使用<bits / stdc ++.h>头文件。
- // minmax example
- #include <iostream> // std::cout
- #include <algorithm> // std::minmax
- using namespace std;
- //C++ STL program to demonstrate use of
- //std::minmax() function
-
- int main()
- {
- int a = -10;
- int b = -20;
-
- //finding pair of smallest and largest numbet
- auto result = minmax(a, b);
-
- //printing the smallest and largest values
- cout << "smallest number is: " << result.first << endl;
- cout << "largest number is: " << result.second << endl;
-
- return 0;
- }

结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。