AI for Humans
Saturday, April 23, 2016
Insertion Sort
Java
public class InsertionSort { public static void sort(int[] in) { for (int i = 1; i < in.length; i++) { int key = in[i]; int j = i - 1; while (j >= 0 && in[j] > key) { in[j + 1] = in[j]; j--; } in[j + 1] = key; } } }
Find on github
No comments:
Post a Comment
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment