Insert Sort
There is already a well-ordered sequence in which to place the new element in the proper position of the sequence.
int *insertsorta (int *r,n) {
int i,j; for (j=1; j<n;j++) {i=j-1; TMP=r[j]; while (i>=0&&R[i]<tmp) { r[i+1]=r[i]; I--; } R[i+1]=tmp; }
return R;}
Each of the above algorithms to determine whether I is less than 0, you can let the first element of the array is a very small value, so that the r[0]<min{ri},i is 1 to n, the entire array length is n+1. When judging r[i]<tmp, it will end, because r[0] must be less than r[i].
int *INSERTSORTB (int *r,n) { int i,j; for (j=2; j++;j<=N) {i=j-1; TMP=r[j]; while (r[i]<tmp) {r[i+1]=r[i]; I--; } r[i+1]=tmp; }
return R;}
Shell sort
The main idea of the shell is that the elements are grouped by a certain increment of the subscript, using the direct insert sort for each group. As the increments gradually decrease, each group contains more and more records. When the increment value is reduced to 1 o'clock, the entire file is split into a group, and the algorithm terminates.
Multiple sorting algorithms