Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <functional>
- template<typename T, typename Compare = std::less<T>() >
- void selection_sort(T first, T last, Compare comp) {
- T start = first;
- if (start == last || start == last - 1) {
- return;
- }
- while (first != last - 1) {
- T min = first;
- start = first + 1;
- while (start != last) {
- if (comp(*start,*min)) {
- min = start;
- }
- start++;
- }
- if (min != first) {
- typename T::value_type tmp = *min;
- *min = *first;
- *first = tmp;
- }
- first++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement