반응형
Sort의 원형이다.
한번 고민해 봐야 할 것 같다.
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 32 33 | void _Sort(_RanIt _First, _RanIt _Last, _Diff _Ideal, _Pr _Pred) { // order [_First, _Last), using _Pred _Diff _Count; for (; _ISORT_MAX < (_Count = _Last - _First) & & 0 < _Ideal;) { // divide and conquer by quicksort pair<_RanIt, _RanIt> _Mid = _Unguarded_partition(_First, _Last, _Pred); _Ideal /= 2; _Ideal += _Ideal / 2; // allow 1.5 log2(N) divisions if (_Mid.first - _First < _Last - _Mid.second) { // loop on second half _Sort(_First, _Mid.first, _Ideal, _Pred); _First = _Mid.second; } else { // loop on first half _Sort(_Mid.second, _Last, _Ideal, _Pred); _Last = _Mid.first; } } if (_ISORT_MAX < _Count) { // heap sort if too many divisions _STD make_heap(_First, _Last, _Pred); _STD sort_heap(_First, _Last, _Pred); } else if (1 < _Count) _Insertion_sort(_First, _Last, _Pred); // small } | cs |
반응형
'ETC > Data Struct | Algorithm' 카테고리의 다른 글
Priority Queue , 우선순위 큐 (0) | 2017.08.06 |
---|---|
Geometry (0) | 2017.07.17 |
Graph - 인접 행렬 그래프 (0) | 2014.06.25 |
이진 탐색 ( Binary Search ) (0) | 2014.05.15 |
순차 검색 (Sequential Search) (0) | 2014.05.15 |