Java Insertion Sort insertionSort(int[] a)

Here you can find the source of insertionSort(int[] a)

Description

insertion Sort

License

Apache License

Declaration

public static void insertionSort(int[] a) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static void insertionSort(int[] a) {
        if (a == null || a.length == 0)
            return;

        for (int i = 1; i < a.length; i++) {
            int unsorted = a[i]; // a[0:i-1] is sorted
            int j = i;
            while (j > 0 && a[j - 1] > unsorted) {
                a[j] = a[j - 1];/* ww w  .ja  va  2s  .c o m*/
                j--;
            }
            a[j] = unsorted;
        }
    }
}

Related

  1. insertionSort(Comparable[] a, int low, int high)
  2. insertionSort(double[] a, int low, int high)
  3. insertionsort(double[] a, int[] b, int p, int r)
  4. insertionSort(int[] a)
  5. insertionsort(int[] array)
  6. insertionSort(int[] input)
  7. insertionSort(int[] target, int[] coSort)
  8. insertionSortInPlaceSwap(int[] xs)