Java Insertion Sort insertionsort(double[] a, int[] b, int p, int r)

Here you can find the source of insertionsort(double[] a, int[] b, int p, int r)

Description

insertionsort

License

Open Source License

Declaration

protected static final void insertionsort(double[] a, int[] b, int p, int r) 

Method Source Code

//package com.java2s;

public class Main {
    protected static final void insertionsort(double[] a, int[] b, int p, int r) {
        for (int j = p + 1; j <= r; ++j) {
            double key = a[j];
            int val = b[j];
            int i = j - 1;
            while (i >= p && a[i] > key) {
                a[i + 1] = a[i];/*from w  w  w .ja v  a  2 s. c  om*/
                b[i + 1] = b[i];
                i--;
            }
            a[i + 1] = key;
            b[i + 1] = val;
        }
    }

    protected static final void insertionsort(long[] a, int[] b, int p, int r) {
        for (int j = p + 1; j <= r; ++j) {
            long key = a[j];
            int val = b[j];
            int i = j - 1;
            while (i >= p && a[i] > key) {
                a[i + 1] = a[i];
                b[i + 1] = b[i];
                i--;
            }
            a[i + 1] = key;
            b[i + 1] = val;
        }
    }

    protected static final void insertionsort(int[] a, int[] b, int p, int r) {
        for (int j = p + 1; j <= r; ++j) {
            int key = a[j];
            int val = b[j];
            int i = j - 1;
            while (i >= p && a[i] > key) {
                a[i + 1] = a[i];
                b[i + 1] = b[i];
                i--;
            }
            a[i + 1] = key;
            b[i + 1] = val;
        }
    }
}

Related

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