01Count instead of compare
Suppose every value is an integer between 0 and k − 1, for example exam grades or ages. Make an array count of size k, all zeros. Scan the input once and for each value v do count[v]++.
For [3, 6, 1, 3, 4, 1, 6, 3] this gives count = [0, 2, 0, 3, 1, 0, 2]: two 1s, three 3s, one 4, two 6s.
If you only need the sorted numbers, you are already done: write each v out count[v] times. Two simple passes, O(n + k), and not a single comparison between elements.