#include <bits/stdc++.h>
using namespace std;
void insertionSort(int arr[], int n)
{
for (int i = 1; i < n; ++i) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
void printArray(int arr[], int n)
{
for (int i = 0; i < n; ++i)
cout << arr[i] << " ";
cout << endl;
}
int main()
{
int arr[] = { 12, 11, 13, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
clock_t begin = clock();
insertionSort(arr, n);
printArray(arr, n);
clock_t end = clock();
cout<<"Time run: "<< fixed << (float)(end-begin)/CLOCKS_PER_SEC<<" s"<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnZvaWQgaW5zZXJ0aW9uU29ydChpbnQgYXJyW10sIGludCBuKQp7CiAgICBmb3IgKGludCBpID0gMTsgaSA8IG47ICsraSkgewogICAgICAgIGludCBrZXkgPSBhcnJbaV07CiAgICAgICAgaW50IGogPSBpIC0gMTsKICAgICAgICB3aGlsZSAoaiA+PSAwICYmIGFycltqXSA+IGtleSkgewogICAgICAgICAgICBhcnJbaiArIDFdID0gYXJyW2pdOwogICAgICAgICAgICBqID0gaiAtIDE7CiAgICAgICAgfQogICAgICAgIGFycltqICsgMV0gPSBrZXk7CiAgICB9Cn0KCnZvaWQgcHJpbnRBcnJheShpbnQgYXJyW10sIGludCBuKQp7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkKICAgICAgICBjb3V0IDw8IGFycltpXSA8PCAiICI7CiAgICBjb3V0IDw8IGVuZGw7Cn0KCmludCBtYWluKCkKewogICAgaW50IGFycltdID0geyAxMiwgMTEsIDEzLCA1LCA2IH07CiAgICBpbnQgbiA9IHNpemVvZihhcnIpIC8gc2l6ZW9mKGFyclswXSk7CiAgICBjbG9ja190IGJlZ2luID0gY2xvY2soKTsgCiAgICBpbnNlcnRpb25Tb3J0KGFyciwgbik7CiAgICBwcmludEFycmF5KGFyciwgbik7CiAgICBjbG9ja190IGVuZCA9IGNsb2NrKCk7IAogICAgY291dDw8IlRpbWUgcnVuOiAiPDwgZml4ZWQgPDwgKGZsb2F0KShlbmQtYmVnaW4pL0NMT0NLU19QRVJfU0VDPDwiIHMiPDxlbmRsOwogICAKCiAgICByZXR1cm4gMDsKfQoK