本文共 741 字,大约阅读时间需要 2 分钟。
性质:每次将一个待排序的元素,按其关键字大小插入到已经排好序的子表中的适当位置,直到全部元素插入完成为止。
//直接插入排序-稳定typedef struct{int key;}RecType;void InsertSort(RecType R[],int n){int i,j;RecType tmp; for(i=1;i=0&&tmp.key
直接插入排序的图解:
//折半插入排序typedef struct{int key;}RecType;void InsertSort(RecType R[],int n){ int i,j,low,high,mid; RecType tmp; for(i=1;i=high+1;j--) R[j+1]=R[j]; R[high+1]=tmp; }}
折半插入排序的图解:
//希尔排序-不稳定typedef struct{int key;}RecType;void ShellSort(RecType R[],int n){ int i,j,gap; RecType tmp; gap=n/2; while(gap>0) { for(i=gap;i=0&&tmp.key
希尔排序的图解:
转载地址:http://swwab.baihongyu.com/