Non-comparison sort for small integer ranges: count each value, then write them back in order. O(n + k) where k is the value range.
void countingSort(vector<int> &a, int maxVal) {
vector<int> cnt(maxVal + 1, 0);
for (int x : a) cnt[x]++;
int idx = 0;
for (int v = 0; v <= maxVal; v++)
while (cnt[v]--) a[idx++] = v;
}