复习一下很古老的排序方法,插入排序:
物理结构:数组
插入排序分析:
最优时间复杂度:O(n) 顺序的情况下
最坏时间复杂度:O(n^2)
平均时间复杂度:O(n^2)
最坏空间复杂度:O(n) 辅助空间O(1)
稳定性:稳定
快速排序法函数:
int InsertSort(int a[],int length);
[cpp] view plaincopy
01.//插入排序
02.int InsertSort(int a[],int length)
03.{
04. int tmp,i,j;
05. for(i=1;i<length;i++)
06. {
07. tmp=a[i];
08. j=i;
09. while(j>0&&a[j-1]>tmp)
10. {
11. a[j]=a[j-1];
12. --j;
13. }
14. a[j]=tmp;
15. }
16.}