#include<iostream>
#include <ctime>
using namespace std;
void Selection_sort(int arr[], int n)
{
int min, i, j;
for (i = 0; i < n - 1; i++)
{
min = i;
for (j = i + 1; j < n; j++)
{
if (arr[j] < arr[min])
{
min = j;
}
}
swap(arr[min], arr[i]);
}
}
int main()
{
int n,i;
cout<<"Enter the size of an array: ";
cin>>n;
int arr[n];
cout<<"Enter the elements: ";
for(i=0; i<n; i++)
{
cin>>arr[i];
}
clock_t start = clock();
Selection_sort(arr,n);
clock_t end = clock();
cout << "Sorted array: ";
for(i=0; i<n; i++)
{
cout<<arr[i]<<" ";
}
double time_taken = double(end - start) / CLOCKS_PER_SEC * 1000;
cout << endl<<"Time taken to sort the array: " << time_taken << " ms" << endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlIDxjdGltZT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgU2VsZWN0aW9uX3NvcnQoaW50IGFycltdLCBpbnQgbikKewogICAgaW50IG1pbiwgaSwgajsKICAgIGZvciAoaSA9IDA7IGkgPCBuIC0gMTsgaSsrKQogICAgewogICAgICAgIG1pbiA9IGk7CiAgICAgICAgZm9yIChqID0gaSArIDE7IGogPCBuOyBqKyspCiAgICAgICAgewogICAgICAgICAgICBpZiAoYXJyW2pdIDwgYXJyW21pbl0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG1pbiA9IGo7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc3dhcChhcnJbbWluXSwgYXJyW2ldKTsKICAgIH0KfQoKCmludCBtYWluKCkKewogICAgaW50IG4saTsKICAgIGNvdXQ8PCJFbnRlciB0aGUgc2l6ZSBvZiBhbiBhcnJheTogIjsKICAgIGNpbj4+bjsKICAgIGludCBhcnJbbl07CiAgICBjb3V0PDwiRW50ZXIgdGhlIGVsZW1lbnRzOiAiOwogICAgZm9yKGk9MDsgaTxuOyBpKyspCiAgICB7CiAgICAgICAgY2luPj5hcnJbaV07CiAgICB9CiAgICBjbG9ja190IHN0YXJ0ID0gY2xvY2soKTsKICAgIFNlbGVjdGlvbl9zb3J0KGFycixuKTsKICAgIGNsb2NrX3QgZW5kID0gY2xvY2soKTsKICAgIGNvdXQgPDwgIlNvcnRlZCBhcnJheTogIjsKICAgIGZvcihpPTA7IGk8bjsgaSsrKQogICAgewogICAgICAgIGNvdXQ8PGFycltpXTw8IiAiOwogICAgfQogICAgZG91YmxlIHRpbWVfdGFrZW4gPSBkb3VibGUoZW5kIC0gc3RhcnQpIC8gQ0xPQ0tTX1BFUl9TRUMgKiAxMDAwOwogICAgY291dCA8PCBlbmRsPDwiVGltZSB0YWtlbiB0byBzb3J0IHRoZSBhcnJheTogIiA8PCB0aW1lX3Rha2VuIDw8ICIgbXMiIDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQo=