Created
April 14, 2017 00:04
-
-
Save artlovan/f29f78f33f2102561f0330bcb7226d27 to your computer and use it in GitHub Desktop.
SelectionSearch in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SelectionSearch { | |
private static int[] data = new int[]{9, 1, 43, 5, 20, 50, 7, 22, 43, 17, 47}; | |
public static void main(String[] args) { | |
System.out.println(Arrays.toString(data)); | |
insertionSort(); | |
System.out.println(Arrays.toString(data)); | |
} | |
public static void insertionSort() { | |
for (int i=0; i < data.length; ++i) { | |
int j = i; | |
int toInsert = data[i]; | |
while ((j > 0) && (data[j - 1]) > toInsert) { | |
data[j] = data[--j]; | |
} | |
data[j] = toInsert; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment