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

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

Description

Internal insertion sort routine for subarrays that is used by quicksort.

License

Open Source License

Parameter

Parameter Description
a an array of Comparable items.
low the left-most index of the subarray.
high the high

Declaration

private static void insertionSort(Comparable[] a, int low, int high) 

Method Source Code

//package com.java2s;
/***********************************************************************
 * mt4j Copyright (c) 2008 - 2009 C.Ruff, Fraunhofer-Gesellschaft All rights reserved.
 *  /*from  w  w w . j a v a  2  s . c  o  m*/
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

public class Main {
    /**
     * 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 high the high
     */
    private static void insertionSort(Comparable[] a, int low, int high) {
        for (int p = low + 1; p <= high; p++) {
            Comparable 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(double[] a, int low, int high)
  2. insertionsort(double[] a, int[] b, int p, int r)
  3. insertionSort(int[] a)
  4. insertionSort(int[] a)