Writing code in Java, Ruby and JavaScript
public static void insertionsort(int[] A) { for (int i = 1; i < A.length; i++) { for (int j = i; j > 0 && A[j] < A[j - 1]; j--) { swap(A, j, j - 1); } } } public static void swap(int[] A, int i, int j) { int temp = A[j]; A[j] = A[i]; A[i] = temp; }
No comments:
Post a Comment