​二分插入法​

​直接插入法​

​冒泡法​

​选择排序法​

​快速排序​

​堆排序​

​归并排序​

`void HalfInsertSort(int a[], int len){int i, j,temp;int low, high, mid;for (i=1; i     {temp = a[i];low = 0;high = i-1;while (low <= high)          {mid = (low + high) / 2;if (a[mid] > temp)                 {high = mid-1;               }else                   {low = mid+1;               }          }      for (j=i-1; j>high; j--)          {a[j+1] = a[j];          }a[high+1] = temp;     }}`

### 直接插入法

`void InsertionSort(int input[],int len) {int i,j,temp;for (i = 1; i < len; i++)      {temp = input[i];  for (j = i - 1;j>-1&&input[j] > temp ; j--)          {input[j + 1] = input[j];input[j] = temp;          }     }}`

### 带哨兵的直接排序法

`void InsertionSortWithPiquet(int input[],int len) {int i,j;for (i = 2; i < len; i++)       {input[0] = input[i];for (j = i - 1; input[j] > input[0] ; j--)           {input[j + 1] = input[j];input[j] = input[0];          }     }}`

`#includevoid sort(int v[],int n){int gap,i,j,temp;for(gap=n/2;gap>0;gap /= 2)     {for(i=gap;i          {for(j=i-gap;(j >= 0) && (v[j] > v[j+gap]);j -= gap )               {temp=v[j];v[j]=v[j+gap];v[j+gap]=temp;               }          }     }}`

### 冒泡法

`void Bublesort(int a[],int n){int i,j,k;for(j=0;j<n;j++)     {for(i=0;i<n-j;i++)          {if(a[i]>a[i+1])                 {k=a[i];a[i]=a[i+1];a[i+1]=k;               }          }     }}`

### 选择排序法

`void Selectsort(int A[],int n) {int i,j,min,temp; for(i=0;i     {min=i; for(j=i+1;j<=n;j++)            {if(A[min]>A[j])                 {temp=A[i]; A[i]=A[j]; A[j]=temp;               }          }    } }`

### 快速排序

`void quickSort(int arr[], int left, int right){if (left > right)    {return;    }int i = left;int j = right;int pivot = arr[left];int tmp   = 0;while (i < j)    {while (i < j && arr[j] >= pivot )        {j--;        }while (i < j && arr[i] <= pivot )        {i++;        }if(i < j)   //交换        {tmp    = arr[i];arr[i] = arr[j];arr[j] = tmp ;        }    }arr[i] = pivot;quickSort3(arr, left, i - 1);quickSort3(arr, i + 1, right);}//交换的地方也可以用C++的 swap()#include<algorithm>swap(arr[i], arr[j]);`

### 堆排序

`void HeapAdjust(int data[],int s,int m){ int j,rc; rc=data[s];    for(j=2*s;j<=m;j*=2)             {if(jif(rc>data[j]) break; data[s]=data[j];  s=j;      } data[s]=rc;    }void Heap_sort(int data[],int long_n){int i,temp; for(i=long_n/2;i>0;--i)       {HeapAdjust(data,i,long_n);     }for(i=long_n;i>0;--i)     {temp=data[1];    data[1]=data[i]; data[i]=temp;   HeapAdjust(data,1,i-1);     }}`