[c++] 插入排序

void InsertionSort(int arr[])
{
    for(int i=1; i < arr.len(); i++)
    {
        int key = arr[i];
 
        int j = i;
        while(key < arr[j-1] && j > 0) 
        {
            //move key to previous position
            arr[j] = arr[j-1];
            j--;
        }
        arr[j] = key; 
 
        PrintArray(arr);
    }
}

  

原文地址:https://www.cnblogs.com/P3nguin/p/7502030.html