C语言插入排序算法

#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;

}

posted @ 2014-10-16 22:15  _boy  阅读(1247)  评论(0编辑  收藏  举报