package Sorting;

public class CountingSorter extends Sorter{

    public CountingSorter(String filename){
        super("counting", filename);
    }

    void sort(){
        int min = numbers[0];
        int max = numbers[0];
        for(int e: numbers){
            if(compare(e,min)<0){
                min=e;
            }
            if(compare(e,max)>0){
                max=e;
            }
        }
        int[] countArray = new int[max-min+1];
        for(int e: numbers){
            countArray[e-min]++;
        }
        int index=0;
        for(int i=0;i<countArray.length;i++){
            while(countArray[i]!=0){
                numbers[index]=i+min;
                index++;
                countArray[i]--;
            }
        }
    }
    
}