桶排序-C

#include <stdio.h>

int main() {
    
    int b[5] = {5,2,3,1,8};
    int a[11],i;
    int length = sizeof(a) / sizeof (int);
    for(i=0;i<length;i++){
        a[i] = 0;
    }
    a[0] = 0;
    
    for (i=0; i<5; i++) {
        int num = b[i];
        if(a[num] >= 0){
            a[num] ++;
        }else{
            a[num] = 0;
        }
    }
    
    for (i=0; i<11; i++) {
        if(a[i])
            printf("%d\n",i);
    }
    
    return 0;
}

 

posted @ 2016-09-22 13:59  levyleo  阅读(168)  评论(0编辑  收藏  举报