#include <bits/stdc++.h>
using namespace std;
void selectionSort(vector<int> &arr) {
int n = arr.size();
for (int i = 0; i < n - 1; ++i) {
int min_idx = i;
for (int j = i + 1; j < n; ++j) {
if (arr[j] < arr[min_idx]) {
min_idx = j;
}
}
swap(arr[i], arr[min_idx]);
}
}
void printArray(vector<int> &arr) {
for (int &val : arr) {
cout << val << " ";
}
cout << endl;
}
int main() {
vector<int> arr = {64, 25, 12, 22, 11};
cout << "Original array: ";
printArray(arr);
clock_t begin = clock();
selectionSort(arr);
cout << "Sorted array: ";
printArray(arr);
clock_t end = clock();
cout<<"Time run: "<<fixed << (float)(end-begin)/CLOCKS_PER_SEC<<"s"<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHNlbGVjdGlvblNvcnQodmVjdG9yPGludD4gJmFycikgewogICAgaW50IG4gPSBhcnIuc2l6ZSgpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuIC0gMTsgKytpKSB7CiAgICAgICAgaW50IG1pbl9pZHggPSBpOwogICAgICAgIGZvciAoaW50IGogPSBpICsgMTsgaiA8IG47ICsraikgewogICAgICAgICAgICBpZiAoYXJyW2pdIDwgYXJyW21pbl9pZHhdKSB7CiAgICAgICAgICAgICAgICBtaW5faWR4ID0gajsgCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc3dhcChhcnJbaV0sIGFyclttaW5faWR4XSk7CiAgICB9Cn0KCnZvaWQgcHJpbnRBcnJheSh2ZWN0b3I8aW50PiAmYXJyKSB7CiAgICBmb3IgKGludCAmdmFsIDogYXJyKSB7CiAgICAgICAgY291dCA8PCB2YWwgPDwgIiAiOwogICAgfQogICAgY291dCA8PCBlbmRsOwp9CgppbnQgbWFpbigpIHsKICAgIHZlY3RvcjxpbnQ+IGFyciA9IHs2NCwgMjUsIDEyLCAyMiwgMTF9OwogICAgY291dCA8PCAiT3JpZ2luYWwgYXJyYXk6ICI7CiAgICBwcmludEFycmF5KGFycik7IAogICAgY2xvY2tfdCBiZWdpbiA9IGNsb2NrKCk7CiAgICBzZWxlY3Rpb25Tb3J0KGFycik7CiAgICBjb3V0IDw8ICJTb3J0ZWQgYXJyYXk6ICI7CiAgICBwcmludEFycmF5KGFycik7CiAgICBjbG9ja190IGVuZCA9IGNsb2NrKCk7IAogICAgY291dDw8IlRpbWUgcnVuOiAiPDxmaXhlZCA8PCAoZmxvYXQpKGVuZC1iZWdpbikvQ0xPQ0tTX1BFUl9TRUM8PCJzIjw8ZW5kbDsKICAgIHJldHVybiAwOwp9Cg==