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