C语言实现直接插入排序

来源:互联网 发布:知乎手机如何回复评论 编辑:程序博客网 时间:2024/05/17 04:28
void insertion_sort(int *array, int first, int last) {    int i, j, temp;    for (i = first + 1; i < last; i++) {    // 默认第一元素有序,从第二个元素开始遍历        temp = array[i];                    // 保存无序区首元素        for (j = i - 1; j >= first && array[j] >= temp; j--) {  // 从有序区末尾开始循环与无序区首元素比较            array[j+1] = array[j];        }        array[j+1] = temp;                      }}
0 0
原创粉丝点击