Nagie's DevStory
[STL] 09. std::stable_sort 본문
728x90
std::stable_sort는 C++ 표준 라이브러리(STL)에서 제공하는 정렬을 수행하는 함수이며,
<algorithm> 헤더에 정의되어 있다.
std::sort와 사용법은 동일하지만, std::stable_sort는 안정성을 유지하면서 정렬하기에
요소의 상대적인 순서가 중요하다면 std::sort 대신 std::stable_sort를 사용해야 한다.
다음은 std::stable_sort의 사용 예시이다.
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> nums = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5};
std::stable_sort(nums.begin(), nums.end());
for (const auto& e : nums) {
std::cout << e << " ";
}
}
[STL] 08. std::sort
std::sort는 C++ 표준 라이브러리(STL)에서 제공하는 정렬을 수행하는 함수이며, 헤더에 정의되어 있다. 기본적으로 오름차순 정렬을 하며, 퀵 정렬(Quick Sort)이나 병합 정렬(Merge Sort)과 같은 알고리즘
nagie.tistory.com
728x90
Comments