반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- centOS
- docker
- C++
- ios
- 도커 컨테이너
- 쿠버네티스
- linux
- swift 클로저
- 네트워크
- NGINX
- Swift
- boj
- 도커
- 컨테이너
- Python
- 도커 명령어
- os
- devops
- 클라우드
- 리눅스
- k8s
- AWS
- 운영체제
- 인프라
- kubernetes
- 도커 이미지
- 부스트코스
- centOS7
- 프로세스
- 데브옵스
Archives
- Today
- Total
귀염둥이의 메모
[C++] sort 이용한 오름차순, 내림차순 정렬, greater<>, less<> 본문
반응형
sort() - 기본 오름차순
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> v = {3, 2, 0, 9, 7, 1, 4, 8, 6};
sort(v.begin(), v.end());
for (int n : v) {
cout << n << ' ';
}
cout << '\n';
return 0;
}
// 0 1 2 3 4 6 7 8 9
sort() + std::less<> - 오름차순
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> v = {3, 2, 0, 9, 7, 1, 4, 8, 6};
sort(v.begin(), v.end(), less<int>());
for (int n : v) {
cout << n << ' ';
}
cout << '\n';
return 0;
}
// 0 1 2 3 4 6 7 8 9
sort() + std::greater<> - 내림차순
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> v = {3, 2, 0, 9, 7, 1, 4, 8, 6};
sort(v.begin(), v.end(), greater<int>());
for (int n : v) {
cout << n << ' ';
}
cout << '\n';
return 0;
}
// 9 8 7 6 4 3 2 1 0
반응형
'CS > C, C++' 카테고리의 다른 글
[C++] STL (Standard Template Library) (0) | 2021.02.17 |
---|---|
[C언어] 포인터(Pointer) (0) | 2021.02.09 |
[C++] std::accumulate (0) | 2021.02.08 |
Comments