MC logo

Radix Sort Example


CS 402 Examples

Original data:

429 448 386 442 628 391 148 381 671 484

In the first phase, we enqueue each datum on a queue named by its last digit. This gives:

0:
1: 391381671
2: 442
3:
4: 484
5:
6: 386
7:
8: 448628148
9: 429

Now, pass through the queues in order (0 to 9), empty each one, and place the data into the list in the order produced by this scan:

391 381 671 442 484 386 448 628 148 429

Now, we repeat by queuing according to the middle digit:

0:
1:
2: 628429
3:
4: 442448148
5:
6:
7: 671
8: 381484386
9: 391

Again, we traverse the queues in order, empty each one, and reconstruct the data:

628 429 442 448 148 671 381 484 386 391

Again, we enqueue the data, this time on the first digit:

0:
1: 148
2:
3: 381386391
4: 429442448484
5:
6: 628671
7:
8:
9:

When we traverse and empty the queues, the result is a sorted list:

148 381 386 391 429 442 448 484 628 671