#define_CRT_SECURE_NO_WARNINGS1#include<iostream>usingnamespace std;//from the front to the backvoidinsert_sort1(int*a,int n){if(n <2)return;int t;//store elem_iint p;//finding the insert point int j;//traverse the sorted_elemfor(int i =1; i < n; i++){int p =0;for(j =0; j <i; j++){if(a[i]< a[j]){
p = j;break;}}if(j!=i){
t = a[i];for(int k = i; k > p; k--)
a[k]= a[k-1];
a[p]= t;}}return;}//from the back to the frontvoidinsert_sort2(int* a,int n){if(n <2)return;int t, j;for(int i =1; i < n; i++){
t = a[i];for(j = i -1; j >=0&& t < a[j]; j--)//a[i] may be covered,so t<a[j] not a[i]<a[j]
a[j +1]= a[j];
a[j +1]= t;}return;}intmain(){int a[]={44,3,38,5,47,15,36,26,27,2,46,4,19,50,48};insert_sort1(a,sizeof(a)/sizeof(a[0]));for(constauto& e : a)
cout << e <<" ";
cout << endl;int b[]={44,3,38,5,47,15,36,26,27,2,46,4,19,50,48};insert_sort2(b,sizeof(b)/sizeof(b[0]));for(constauto& e : b)
cout << e <<" ";
cout << endl;return0;}