Files
Tutoring-APCompSci/Sorting/SelectionSorter.java
2020-06-11 14:06:24 -05:00

21 lines
610 B
Java

package Sorting;
public class SelectionSorter extends Sorter {
//a class to sort an array of numbers using selection sort
public SelectionSorter(RandomNumberFileReader reader){
super("selection sort", reader);
}
void sort(){
for(int i=0;i<numbers.length-1;i++){
int currentMinIndex = i;
for(int j=i+1;j<numbers.length;j++){
int comp = compare(numbers[currentMinIndex],numbers[j]);
if(comp>0){
currentMinIndex = j;
}
}
swap(i,currentMinIndex);
}
}
}