#include <iostream>
using namespace std;
int main() {
int n;
int i,j,temp;
cout << "Please enter array elements size to sort" << endl;
cin >> n;
int a[n];
cout << endl << "Please enter array of size " << n << endl;
for(i=0;i<n;i++){
cin >> a[i];
}
cout << endl << "the array before sorting is: " << endl;
for(i=0;i<n;i++){
cout << a[i] << "\t";
}
/* insertion sort */
for(i=1;i<n;i++){
for(j=0;j<i;j++){
if(a[i] < a[j]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
cout << endl << "the array after sorting is: " << endl;
for(i=0;i<n;i++){
cout << a[i] << "\t";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkgaW50IG47CgkgaW50IGksaix0ZW1wOwoJIAoJIGNvdXQgPDwgIlBsZWFzZSBlbnRlciBhcnJheSBlbGVtZW50cyBzaXplIHRvIHNvcnQiIDw8IGVuZGw7CgkgY2luID4+IG47CgkgCgkgaW50IGFbbl07CgoJIGNvdXQgPDwgZW5kbCA8PCAgIlBsZWFzZSBlbnRlciBhcnJheSBvZiBzaXplICIgPDwgbiA8PCBlbmRsOwoJCSAgCSAKCSBmb3IoaT0wO2k8bjtpKyspewogICAgICAgCWNpbiA+PiBhW2ldOwkJICAKICAgICB9CgkgCgkgY291dCA8PCBlbmRsIDw8ICAidGhlIGFycmF5IGJlZm9yZSBzb3J0aW5nIGlzOiAiIDw8IGVuZGw7CgkgCgkgIGZvcihpPTA7aTxuO2krKyl7CiAgICAgICAgY291dCA8PCBhW2ldIDw8ICJcdCI7CiAgICAgIH0JCgkgIAoJICAvKiBpbnNlcnRpb24gc29ydCAqLwoJICBmb3IoaT0xO2k8bjtpKyspewoJICAJZm9yKGo9MDtqPGk7aisrKXsKCQkJIGlmKGFbaV0gPCBhW2pdKXsKIAkJICAgICAgICAgIHRlbXAgPSBhW2ldOwogCQkgICAgICAgICAgYVtpXSA9IGFbal07CiAJCSAgICAgICAgICBhW2pdID0gdGVtcDsKCQkJIH0KCQl9CSAgIAoJICB9IAkKCSAgCgkgIGNvdXQgPDwgZW5kbCA8PCAgInRoZSBhcnJheSBhZnRlciBzb3J0aW5nIGlzOiAiIDw8IGVuZGw7CgkgIAogICAgICBmb3IoaT0wO2k8bjtpKyspewogICAgICAgIGNvdXQgPDwgYVtpXSA8PCAiXHQiOwogICAgICB9CSAKCSAJCglyZXR1cm4gMDsKfQ==