Added check that counting array isn't empty; avoids crash when file does not exist
This commit is contained in:
@@ -7,26 +7,28 @@ public class CountingSorter extends Sorter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sort(){
|
void sort(){
|
||||||
int min = numbers[0];
|
if(numbers.length!=0){
|
||||||
int max = numbers[0];
|
int min = numbers[0];
|
||||||
for(int e: numbers){
|
int max = numbers[0];
|
||||||
if(compare(e,min)<0){
|
for(int e: numbers){
|
||||||
min=e;
|
if(compare(e,min)<0){
|
||||||
|
min=e;
|
||||||
|
}
|
||||||
|
if(compare(e,max)>0){
|
||||||
|
max=e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(compare(e,max)>0){
|
int[] countArray = new int[max-min+1];
|
||||||
max=e;
|
for(int e: numbers){
|
||||||
|
countArray[e-min]++;
|
||||||
}
|
}
|
||||||
}
|
int index=0;
|
||||||
int[] countArray = new int[max-min+1];
|
for(int i=0;i<countArray.length;i++){
|
||||||
for(int e: numbers){
|
while(countArray[i]!=0){
|
||||||
countArray[e-min]++;
|
numbers[index]=i+min;
|
||||||
}
|
index++;
|
||||||
int index=0;
|
countArray[i]--;
|
||||||
for(int i=0;i<countArray.length;i++){
|
}
|
||||||
while(countArray[i]!=0){
|
|
||||||
numbers[index]=i+min;
|
|
||||||
index++;
|
|
||||||
countArray[i]--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user