1#ifndef ALGOPLUS_COUNTING_SORT_H
2#define ALGOPLUS_COUNTING_SORT_H
15template <
typename T>
void counting_sort(std::vector<T>& arr) {
16 T maxElement = std::max(0, *max_element(arr.begin(), arr.end()));
17 std::vector<T> count(maxElement + 1, 0);
18 std::vector<T> output(arr.size());
21 for (int64_t i = 0; i < arr.size(); i++) {
27 for (int64_t i = 1; i <= maxElement; i++) {
28 count[i] += count[i - 1];
32 for (int64_t i = arr.size() - 1; i >= 0; i--) {
33 output[count[arr[i]] - 1] = arr[i];