|
|
- #pragma once
- #include <gp/algorithms/move.hpp>
-
- namespace gp {
- template<typename it_t, typename pred>
- void selection_sort(it_t first, it_t last, pred predicate = pred{}) {
-
- while(first != last) {
- auto traveler = first;
- auto it = first;
- it++;
- for(;it!=last;it++) {
- if(predicate(*it, *traveler)) traveler = it;
- }
- gp::swap(*first, *traveler);
- first++;
- }
- }
-
-
- template<typename it_t, typename pred>
- void sort(it_t first, it_t last, pred predicate = pred{}) {
- return selection_sort(first, last, predicate);
- }
- }
|