관리 메뉴

Kim's Programming

Algorithm - partial_sort() 본문

STL - Algorithm/Algorithm - Sorting

Algorithm - partial_sort()

Programmer. 2017. 6. 30. 12:28

원형)


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



의미)


Iterator first 와 Iterator middle까지의 데이터를 정렬합니다.  



소스)


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(std::vector<int> Target_Vector)
{
    for (std::vector<int>::iterator IterPos = Target_Vector.begin(); IterPos != Target_Vector.end(); ++IterPos)
        std::cout << *IterPos << " ";
    std::cout << std::endl;
}
void main() 
{
    std::vector<int> Vector = { 255,15,10,20,30,15 };
    print(Vector);
    std::partial_sort(Vector.begin(), Vector.begin() + 3, 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 - stable_sort()  (0) 2017.06.30
Algorithm - sort()  (0) 2017.06.30