计数排序
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数组中含负数,可通过偏移的方式来避免数组越界

浙公网安备 33010602011771号