STL
4개로 구성되어 있다. (이것들을 미리 만들어 놓은 라이브러리이다.)
-algorithms <- 지금 여기
-containers
-functions
-literators
1. std::stable_sort
https://zoosso.tistory.com/1085
stable_sort()와 sort() 차이 알아보기
배열이나 vector 원소를 정렬하는데 있어서 자주 사용되는 sort() C++에는 stable_sort()라는 것도 있다. 📌 [C++] sort() 함수란? [C++] sort() 함수란? 개발할 때나 코딩 테스트에서 많이 활용되는 정렬(Sort)
zoosso.tistory.com
사용방법 :
#include <algorithm>
bool cmp(member a, member b) {
return a.age < b.age;
}
vector <member> sv;
stable_sort(sv.begin(), sv.end(), cmp);
sv는 벡터이다.
sv.begin()은 벡터 sv의 0번 인덱스(시작점)의 주솟값이다.
sv.end()는 벡터 sv의 마지막 인덱스(끝점)의 주솟값이다.
cmp는 비교하는 함수이다. bool값을 리턴하여, return 첫 번째 인자 < 두 번째 인자 이면 오름차순,
return 첫 번째 인자 > 두 번째 인자 이면 내림차순으로 정렬한다.
stable_sort는 내부적으로 merge sort로 구현되어 있다.
merge sort는
이런 시간 복잡도를 가지고 있다. 즉, 항상 O(n x log n)의 시간 복잡도를 보장하는 정렬 알고리즘이다.
https://www.geeksforgeeks.org/stable_sort-c-stl/
stable_sort() in C++ STL - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
www.geeksforgeeks.org
2. std::max함수
#include <algorithm>
using namespace std;
int a=1;
int b=2;
cout<<max(a,b);이면 둘 중에 큰 수인 a를 리턴한다.
▶ std::max 함수 원형
헤더 : <algorithm>
template<class T>
const T& max (const T& a, const T& b)
https://blockdmask.tistory.com/366
[C++] 최초값, 최대값 함수 min, max 에 대해서 (클래스, vector 사용법까지)
여러분 펭하펭하. BlockDMask 입니다.오늘은 C++에서 최소값, 최대값을 구할수 있는 std::min, std::max 함수의 정의에 대해서 알아보고,1. 기본적인 사용법2. 클래스를 min max에 넣는 방법3. vector에서 min, ma
blockdmask.tistory.com
'c++' 카테고리의 다른 글
[C++] 절댓값 구하기 (0) | 2023.02.27 |
---|---|
[C++] STL - containers (0) | 2023.02.25 |
[c++] STL (0) | 2023.02.20 |
[c++]-STL-컨테이너-string (0) | 2023.02.20 |
[c++] STL - 컨테이너 - vector (0) | 2023.02.20 |