initial commit
This commit is contained in:
23
Sorting/WordSelectionSorter.java
Normal file
23
Sorting/WordSelectionSorter.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package Sorting;
|
||||
|
||||
public class WordSelectionSorter extends WordSorter{
|
||||
|
||||
public WordSelectionSorter(RandomWordFileReader reader){
|
||||
super("selection sort", reader);
|
||||
}
|
||||
|
||||
void sort(){
|
||||
for(int i=0;i<words.length-1;i++){
|
||||
int currentMinIndex = i;
|
||||
for(int j=i+1;j<words.length;j++){
|
||||
int comp = compare(words[currentMinIndex],words[j]);
|
||||
if(comp>0){
|
||||
currentMinIndex = j;
|
||||
}
|
||||
}
|
||||
swap(words,i,currentMinIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user