插入排序

Insert Sorting

void insertSort(int a[], int n)
{
    int i = 0, j = 0, temp = 0;
    for(i = 1; i < n; i++)
    {
        temp = a[i];
        j = i - 1;
        while(temp < a[j] && j >= 0)        
            a[j+1] = a[j--];
        a[j+1] = temp;        
    }
}

O(n^2)

原文地址:https://www.cnblogs.com/alexeyqian/p/3388941.html