Radix Sort: Descending
Here is my RadixSort function (ascending): void RadixSort (int a[], int n) { int i, m=0, exp=1, b[MAX]; for (i=0; i<n; i++) { if (a[i]>m) m=a[i]; } while (m/exp>0) { int bucket[10]={0}; for (i=0; i<n; i++) bucket[a[i]/exp%10]++; for (i=1; i<10; i++) bucket[i]+=bucket[i-1]; for (i=n-1; i>=0; i--) b[--bucket[a[i]/exp%10]]=a[i]; for (i=0; i<n;i++){ a[i]=b[i]; } exp*=10; } } I'm try to change this to a descending sort by replacing for (i=0; i<n;i++) { a[i]=b[i]; } with for (i=0; i<n;i++) { a[i]=b[n-i-1]; } But it didn't work. I tried with: [705, 1725, 99, 9170, 7013] But the result is: [9170, 7013