#include <stdio.h>
void radixSort(int array[], int length){
int countArray[10];
int tempArray[length];
int max = array[0];
for(int i = 1; i < length - 1; i++){
if(array[i] > max){
max = array[i];
}
}
int bitCount = 1;
while((max = max / 10) > 0){
bitCount++;
}
for(int i = 1; bitCount > 0; i *= 10, bitCount--){
for(int i = 0; i < 10; i++){
countArray[i] = 0;
}
for(int i = 0; i < length; i++){
tempArray[i] = 0;
}
for(int j = 0; j < length; j++){
countArray[(array[j] / i) % 10]++;
}
for(int j = 1; j < 10; j++){
countArray[j] += countArray[j - 1];
}
for(int j = length - 1; j >= 0; j--){
tempArray[countArray[(array[j] / i) % 10] - 1] = array[j];
countArray[(array[j] / i) % 10]--;
}
for(int j = 0; j < length; j++){
array[j] = tempArray[j];
}
}
}
int main () {
int array[] = {21, 4, 35, 35, 58, 233, 27, 81, 50, 100};
int length = sizeof(array) / sizeof(array[0]);
radixSort(array, length);
for(int i = 0; i < length; i++){
printf("%d ", array[i]);
}
return 0;
}