#include <iostream>
#include <algorithm>
#include <vector>
std::vector<int> &selection_sort (std::vector<int> &v)
{
for (auto it = v.begin(); it != v.end() - 1; ++it)
{
auto smallest = std::min_element (it + 1, v.end());
std::cout << "it = " << *it << std::endl;
std::cout << "(it + 1) = " << *(it + 1) << std::endl;
std::cout << "smallest = " << *smallest << std::endl;
std::swap (it, smallest);
}
return v;
}
int main()
{
std::vector<int> v = {8, 2, 3, 4, 7, 1, 5, 9, 6, 10};
v = selection_sort (v);
for (auto &i : v)
std::cout << i << " ";
std::cout << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgoKCnN0ZDo6dmVjdG9yPGludD4gJnNlbGVjdGlvbl9zb3J0IChzdGQ6OnZlY3RvcjxpbnQ+ICZ2KQp7CiAgICAgICAgZm9yIChhdXRvIGl0ID0gdi5iZWdpbigpOyBpdCAhPSB2LmVuZCgpIC0gMTsgKytpdCkKICAgICAgICB7CiAgICAgICAgICAgICAgICBhdXRvIHNtYWxsZXN0ID0gc3RkOjptaW5fZWxlbWVudCAoaXQgKyAxLCB2LmVuZCgpKTsKICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCAiaXQgPSAiIDw8ICppdCA8PCBzdGQ6OmVuZGw7CiAgICAgICAgICAgICAgICBzdGQ6OmNvdXQgPDwgIihpdCArIDEpID0gIiA8PCAqKGl0ICsgMSkgPDwgc3RkOjplbmRsOwogICAgICAgICAgICAgICAgc3RkOjpjb3V0IDw8ICJzbWFsbGVzdCA9ICIgPDwgKnNtYWxsZXN0IDw8IHN0ZDo6ZW5kbDsKICAgICAgICAgICAgICAgIHN0ZDo6c3dhcCAoaXQsIHNtYWxsZXN0KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHY7Cn0KCmludCBtYWluKCkKewogICAgICAgIHN0ZDo6dmVjdG9yPGludD4gdiA9IHs4LCAyLCAzLCA0LCA3LCAxLCA1LCA5LCA2LCAxMH07CiAgICAgICAgdiA9IHNlbGVjdGlvbl9zb3J0ICh2KTsKICAgICAgICBmb3IgKGF1dG8gJmkgOiB2KQogICAgICAgICAgICAgICAgc3RkOjpjb3V0IDw8IGkgPDwgIiAiOwogICAgICAgIHN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7Cn0K