Skip to content

Instantly share code, notes, and snippets.

@artlovan
Created April 14, 2017 00:04
Show Gist options
  • Save artlovan/f29f78f33f2102561f0330bcb7226d27 to your computer and use it in GitHub Desktop.
Save artlovan/f29f78f33f2102561f0330bcb7226d27 to your computer and use it in GitHub Desktop.
SelectionSearch in Java
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