initial commit
This commit is contained in:
22
Sorting/WordInsertionSorter.java
Normal file
22
Sorting/WordInsertionSorter.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package Sorting;
|
||||||
|
|
||||||
|
public class WordInsertionSorter extends WordSorter {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user