Counting Sort 1

  • + 0 comments

    C#:

    public static List<int> countingSort(List<int> arr)
        {
            // Initialize a frequency List<int> with 100 elements, all set to 0
            List<int> result = new List<int>(new int[100]);
            
            // Iterate through the input list and count the occurrences
            foreach (int num in arr)
            {
                result[num]++;
            }
            
            // Return the frequency list
            return result;
        }