#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
using namespace std;
int main(void) {
srand((int)time(NULL)); // for creating random number
vector<int> v;
int n = 10;
for (int i = 0; i < n; i++) {
v.push_back(rand() % 10);
}
sort(v.begin(), v.end());
return 0;
}
내림차순
큰 수부터 앞에 정렬하고 싶을 때
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
using namespace std;
int main(void) {
srand((int)time(NULL)); // for creating random number
vector<int> v;
int n = 10;
for (int i = 0; i < n; i++) {
v.push_back(rand() % 10);
}
sort(v.begin(), v.end(), greater<int>());
return 0;
}
오름차순
작은 수부터 앞에 정렬하고 싶을 때
내림차순
큰 수부터 앞에 정렬하고 싶을 때