排序 插入排序

Posted thefist11

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了排序 插入排序相关的知识,希望对你有一定的参考价值。

1. 思想

将无序区的数据插入到有序区

void insertionSort(int arr[], int len) 
    for (int i = 1; i < len; i++) 
        int key = arr[i];
        int j = i - 1;
        while ((j >= 0) && (key < arr[j])) 
            arr[j + 1] = arr[j];
            j--;
        
        arr[j + 1] = key;
    

以上是关于排序 插入排序的主要内容,如果未能解决你的问题,请参考以下文章