计数排序

 1 void countintSort(int array[], int n) {
 2     int count[maxSize] = {0};
 3 
 4     int i;
 5     for (i = 0; i < n; ++i) {
 6         ++count[array[i]];
 7     }
 8 
 9     int counter = 0;
10     for (i = 0; i < maxSize; ++i) {
11         while (count[i]--) {
12             array[counter++] = i;
13         }
14     }
15 }
16 //若array数组中含负数,可通过偏移的方式来避免数组越界
计数排序

 

posted @ 2020-04-20 15:23  小茗从不写博客  阅读(85)  评论(0)    收藏  举报