1.sort(a,a+n)
排序函数
https://blog.csdn.net/w_linux/article/details/76222112
#include<iostream>
#include<algorithm>
using namespace std;
bool Ascending(int i, int j) {
return i < j;
}
bool Descending(int i, int j) {
return i > j;
}
int main() {
int a[10] = { 1,5,2,3,4,5,8,9,6,5 };
sort(a, a + 10);
for (int i = 0; i < 10; i++) {
cout << a[i] << " ";
}
sort(a, a + 10, Descending);
for (int i = 0; i < 10; i++) {
cout << a[i] << " ";
}
return 0;
}
2.vector<int>
不定长数组、向量