#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::iter_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+ICZ2KQp7Cglmb3IgKGF1dG8gaXQgPSB2LmJlZ2luKCk7IGl0ICE9IHYuZW5kKCkgLSAxOyArK2l0KQoJewoJCWF1dG8gc21hbGxlc3QgPSBzdGQ6Om1pbl9lbGVtZW50IChpdCArIDEsIHYuZW5kKCkpOwoJCXN0ZDo6Y291dCA8PCAiaXQgPSAiIDw8ICppdCA8PCBzdGQ6OmVuZGw7CgkJc3RkOjpjb3V0IDw8ICIoaXQgKyAxKSA9ICIgPDwgKihpdCArIDEpIDw8IHN0ZDo6ZW5kbDsKCQlzdGQ6OmNvdXQgPDwgInNtYWxsZXN0ID0gIiA8PCAqc21hbGxlc3QgPDwgc3RkOjplbmRsOwoJCXN0ZDo6aXRlcl9zd2FwIChpdCwgc21hbGxlc3QpOwoJfQoJcmV0dXJuIHY7Cn0KCmludCBtYWluKCkKewoJc3RkOjp2ZWN0b3I8aW50PiB2ID0gezgsIDIsIDMsIDQsIDcsIDEsIDUsIDksIDYsIDEwfTsKCXYgPSBzZWxlY3Rpb25fc29ydCAodik7Cglmb3IgKGF1dG8gJmkgOiB2KQoJCXN0ZDo6Y291dCA8PCBpIDw8ICIgIjsKCXN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7Cn0=