编辑代码

#include <stdio.h>

void countSort(int arr[], int len, int orderArr[]){
    //统计的数组
    int count [len];

    for(int i = 0; i < len; ++i){
        count[i] = 0;
    }

    //统计比计数数组索引对于的元素
    for(int i = 0; i < len; ++i){
        for(int j = i + 1; j < len; ++j){
            if(arr[i] < arr[j]){
                count[j] = count[j] + 1;
            }else{
                count[i] = count[i] + 1;
            }
        }
    }

    //排序
    for(int i = 0; i < len; ++i){
        orderArr[count[i]] = arr[i];
    }
}

int main () {
    int arr[6] = {28,34,18,54,137,85};
    int orderArr[6];
    countSort(arr,6,orderArr);
    for(int i = 0; i < 6; ++i){
        printf("%d ",orderArr[i]);
    }
    return 0;
}