Counting Sort 2

  • + 1 comment

    This is the simplest algorithm I used, sharing 'cause I see a lot of twisted answers here in Discussions

    (C++)

    vector<int> countingSort(vector<int> arr) {
        vector<int> result(100,0);
        vector<int> sorted;
        for(int i=0;i<arr.size();i++)
            result[arr[i]]++;
        
        for(int i=0;i<result.size();i++)
            while(result[i]--)
                sorted.push_back(i);
        
        return sorted;
    }