22 lines
553 B
Java
22 lines
553 B
Java
package Sorting;
|
|
|
|
public class WordInsertionSorter extends Sorter {
|
|
|
|
public WordInsertionSorter(RandomWordFileReader reader){
|
|
super("insertion sort", reader);
|
|
}
|
|
|
|
void sort(){
|
|
String insertionValue;
|
|
for(int i=1;i<words.length;i++){
|
|
insertionValue=words[i];
|
|
int j=i-1;
|
|
while(j>=0 && compare(words[j],insertionValue)>0){
|
|
writeToArray(words, j+1, words[j]);
|
|
j--;
|
|
}
|
|
writeToArray(words, j+1, insertionValue);
|
|
}
|
|
}
|
|
|
|
} |