Advertisement

常见排序算法概述

阅读量:

1.排序算法

1.1 插入排序

1.1.1 概念

1.1.2 代码

复制代码
    void insertionSort(int arr[], int len)
    {
    int insertPosi;
    
    for (int i = 0; i < len; i++)
    {
        insertPosi = 0;                     //can't find the bigger position then keep the insertPosi 0
        //find the insert position
        for (int j = i - 1; j >= 0; j--)
        {
            if (arr[j] <= arr[i])
            {
                insertPosi = j + 1;         //insert at arr[j + 1], minimum of inserPosi is 1 int the loop;
                break;
            }
        }
    
    
        //same position 

全部评论 (0)

还没有任何评论哟~