Java Insertion Sort insertionSort(double[] a, int low, int high)

Here you can find the source of insertionSort(double[] a, int low, int high)

Description

insertion Sort

License

Apache License

Declaration

public static void insertionSort(double[] a, int low, int high) 

Method Source Code

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

public class Main {
    public static void insertionSort(double[] a, int low, int high) {
        for (int p = low + 1; p <= high; p++) {
            double tmp = a[p];
            int j;
            for (j = p; j > low && tmp < (a[j - 1]); j--) {
                a[j] = a[j - 1];/* w w w  .j a  v  a  2 s .c o  m*/
            }
            a[j] = tmp;
        }
    }

    /**
     * Internal insertion sort routine for subarrays that is used by quicksort.
     * 
     * @param a
     *          an array of Comparable items.
     * @param low
     *          the left-most index of the subarray.
     * @param n
     *          the number of items to sort.
     */
    private static <T extends Comparable<T>> void insertionSort(T[] a, int low, int high) {
        for (int p = low + 1; p <= high; p++) {
            T tmp = a[p];
            int j;
            for (j = p; j > low && tmp.compareTo(a[j - 1]) < 0; j--) {
                a[j] = a[j - 1];
            }
            a[j] = tmp;
        }
    }
}

Related

  1. insertionSort(Comparable[] a, int low, int high)
  2. insertionsort(double[] a, int[] b, int p, int r)
  3. insertionSort(int[] a)
  4. insertionSort(int[] a)
  5. insertionsort(int[] array)