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

C语言插入排序算法

时间:2014-10-17 01:25:43      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   sp   ef   bs   算法   c语言   return   

#include <stdio.h>

#define kCount 10

int main()

{

    int array[kCount] = {92, 77, 67, 8, 6, 84, 55, 85, 43, 67};

      for (int i = 1; i<kCount; i++) {     

        int temp = array[i];

        int j = i-1;

        while (temp<array[j]) { 

            array[j+1] = array[j];

            j--;

            if (j==-1) {

                break;

            }

        }

        array[j+1] = temp;       

        }  

    for (int i = 0; i<kCount; i++) {      

        printf("%d\t", array[i]);

    }

    return 0;

}

C语言插入排序算法

标签:io   ar   for   sp   ef   bs   算法   c语言   return   

原文地址:http://www.cnblogs.com/-boy/p/4029844.html

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