#### 1.插入排序

##### 1.1直接插入排序

`void insertSort(void *A, int n){  for(int i = 1; i < n; i++){  //从i=1开始，进行n-1趟排序    int temp = A[i], j = i;    while(A[j] < A[j-1] && j > 0){ //j>0防止A[j-1]数组越界      temp = A[j-1];      A[j-1] = A[j];      A[j] = temp;      j--;    }//将A[i]插入前i个有序队列中  }}`

##### 1.2折半插入排序

`void insertSort(void *A, int n){  int temp, i, j, mid, begin, end;  for(i = 1; i < n; i++){    temp = A[i];    begin = 0, end = i - 1;    while(begin <= end){ //折半查找      mid = (begin + end) / 2; //折半      if(A[mid] > temp)  end = mid - 1;  //查左半表      else  begin = mid + 1;  //查右半表    }    for(j = i - 1; j >= end + 1; j--)  //统一移动      A[j + 1] = A[j];    A[end + 1] = temp;  }}`

##### 1.3希尔排序

`void ShellSort(void A[], int n){  int temp, i, j, d;  for(d = n / 2; d >= 1; d /= 2){  //步长d的设置    for(i = d; i < n; i++){      if(A[i] < A[i - d]){        temp = A[i];        for(j = i - d; j > 0 && temp < A[j]; j -= d)          A[j + d] = A[j];  //记录后移，查找插入位置        A[j + d] = temp;      }    }  } }`