lijing:q 2.1-2降序排列

来源:互联网 发布:ubuntu rc0.d 编辑:程序博客网 时间:2024/05/21 08:56

 

#include <stdio.h>

#include <stdlib.h>

 

int 

main(int argc, char * argv[])

{

    int array[] = {3,6,4,8,1,0};

    int for_count;

    int key = 0;

    int i;

 

    for (for_count = 1; for_count < sizeof(array)/sizeof(int); ++for_count) {

        key = array[for_count];

        i = for_count - 1;

        while ((i >= 0) && (array[i] < key)) {

            array[i+1] = array[i];

            i = i - 1;

        }

        array[i+1] = key;

    }

 

    for (int j = 0; j < 6; ++j)

    {

        printf ("%d/n", array[j]);

    }

    return 0;

}