1. 程式人生 > >STL學習

STL學習

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>

不定長陣列、向量

https://blog.csdn.net/fanyun_01/article/details/56842637