码迷,mamicode.com
首页 > 编程语言 > 详细

[c++] 插入排序

时间:2017-09-10 20:43:50      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:插入   int   []   i++   key   插入排序   for   ons   pre   

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);
    }
}

  

[c++] 插入排序

标签:插入   int   []   i++   key   插入排序   for   ons   pre   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!