관리 메뉴

Kim's Programming

Algorithm - stable_sort() 본문

STL - Algorithm/Algorithm - Sorting

Algorithm - stable_sort()

Programmer. 2017. 6. 30. 11:28

원형)


1
2
3
4
5
6
7
8
//기본형
template <class RandomAccessIterator>
  void stable_sort ( RandomAccessIterator first, RandomAccessIterator last );
 
//사용자 정의형
template <class RandomAccessIterator, class Compare>
  void stable_sort ( RandomAccessIterator first, RandomAccessIterator last,
                     Compare comp );
cs



의미)


std:order()과 같이 [Iterator first, Iterator last)사이에 있는 원소들을 오름차순으로 정렬하지만 동일 값에 대한 원소들의 순서도 고려하여 정렬합니다.



소스)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <algorithm>
#include <vector>
 
void Print(const std::vector<int>& target)
{
    for (std::vector<int>::const_iterator iterPos = target.cbegin(); iterPos != target.cend(); iterPos++)
        std::cout << *iterPos << " ";
    std::cout << std::endl;
}
 
void main()
{
    std::vector<int> vector = { 25,5,15,10,20,30,15 };
    Print(vector);
    std::stable_sort(vector.begin(), vector.end());
    Print(vector);
}
cs



리턴값)


없음



결과)






'STL - Algorithm > Algorithm - Sorting' 카테고리의 다른 글

Algorithm - is_sorted_until()  (0) 2017.06.30
Algorithm - is_sorted()  (0) 2017.06.30
Algorithm - partial_sort_copy()  (0) 2017.06.30
Algorithm - partial_sort()  (0) 2017.06.30
Algorithm - sort()  (0) 2017.06.30