直接插入排序

来源:互联网 发布:2017网络原创歌手 编辑:程序博客网 时间:2024/06/06 07:52
void Insertsort(int a[], int n){int i, j;for (i = 1; i < n; i++){if (a[i] < a[i - 1]){int temp = a[i];for (j = i - 1; j >= 0 && a[j] > temp; j--){a[j + 1] = a[j];}a[j + 1] = temp;}}}


 思想就是:扩大有序区,缩小无序区。

0 0
原创粉丝点击