Radix Sort

Sort digit by digit, from least to most substantial.

Radix sort: Sort digit by digit using stable counting sort.

1.1. Find max to know digit count.

2.2. For each digit position, counting sort on that digit.

Example [170,45,75,90,802,24,2,66][170, 45, 75, 90, 802, 24, 2, 66]:

  • Ones: [170,90,802,2,24,45,75,66][170, 90, 802, 2, 24, 45, 75, 66]
  • Tens: [802,2,24,45,66,170,75,90][802, 2, 24, 45, 66, 170, 75, 90]
  • Hundreds: [2,24,45,66,75,90,170,802][2, 24, 45, 66, 75, 90, 170, 802]

Each pass stable, preserving earlier order when equal.