Refactor to use writeToArray() method
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package Sorting;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CountingSorter extends Sorter{
|
||||
|
||||
public CountingSorter(String filename){
|
||||
@@ -18,18 +20,18 @@ public class CountingSorter extends Sorter{
|
||||
max=e;
|
||||
}
|
||||
}
|
||||
int[] countArray = new int[max-min+1];
|
||||
Integer[] countArray = new Integer[max-min+1];
|
||||
Arrays.fill(countArray, Integer.valueOf(0));
|
||||
for(int e: numbers){
|
||||
countArray[e-min]++;
|
||||
writesUsed++;
|
||||
writeToArray(countArray, e-min, countArray[e-min]+1);
|
||||
|
||||
}
|
||||
int index=0;
|
||||
for(int i=0;i<countArray.length;i++){
|
||||
while(countArray[i]!=0){
|
||||
numbers[index]=i+min;
|
||||
writesUsed++;
|
||||
writeToArray(numbers, index, i+min);
|
||||
index++;
|
||||
countArray[i]--;
|
||||
writeToArray(countArray, i, countArray[i]-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user