- sort 函数
int a[10]={9,6,3,8,5,2,7,4,1,0};
sort(a,a+10)
#include<iostream>
#include<algorithm>
using namespace std;
bool complare(int a,int b) {
return a>b;
}
int main() {
int a[10]={9,6,3,8,5,2,7,4,1,0};
sort(a,a+10, complare);
for(int i=0;i<10;i++)
cout<<a[i]<<" ";
return 0;
}
2 swap 函数
int a=1, b=2;
swap(a,b);
3.max函数
int a=1, b=2;
cout<<max(a,b)<<' '; // 输出 2
cout<<min(a,b); // 输出1
本文通过具体代码示例,介绍了C++标准库中sort、swap及max函数的使用方法。首先,演示了如何使用sort函数对整型数组进行降序排序;其次,展示了swap函数交换两个变量值的过程;最后,解释了max函数用于比较并返回两个数值中较大者的功能。
700

被折叠的 条评论
为什么被折叠?



