Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- template<typename IT, typename FUNC>
- void selection_sort(IT b, IT e, FUNC comp)
- {
- for (auto it = b; it != e; ++it)
- {
- auto min_idx = it;
- auto it2 = it++;
- for (; it2 != e; ++it2) {
- if (comp(*it2, *min_idx)) {
- min_idx = it2;
- }
- }
- auto t = *min_idx;
- *min_idx = *b;
- *b = t;
- }
- }
- template<typename IT>
- void selection_sort(IT b, IT e)
- {
- for (auto it = b; it != e; ++it)
- {
- auto min_idx = it;
- auto it2 = it++;
- for (; it2 != e; ++it2) {
- if ((*it2) < (*min_idx)) {
- min_idx = it2;
- }
- }
- auto t = *min_idx;
- *min_idx = *b;
- *b = t;
- }
- }
- int main()
- {
- std::vector<int> v = {1, 3, 2};
- selection_sort(v.begin(), v.end());
- // for (int c : v) {
- // std::cout<<c<<std::endl;
- // }
- }
- //https://www.geeksforgeeks.org/selection-sort/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement