Java Quick Sort quicksort(final long[] data, final int left, final int right)

Here you can find the source of quicksort(final long[] data, final int left, final int right)

Description

quicksort

License

Open Source License

Declaration

public static void quicksort(final long[] data, final int left, final int right) 

Method Source Code

//package com.java2s;

public class Main {
    public static void quicksort(final long[] data, final int left, final int right) {
        if (data == null || data.length < 2)
            return;
        int i = left, j = right;
        long x = data[(left + right) / 2];
        do {/*from   w  w  w . j av  a2  s  .c  o m*/
            while (data[i] < x)
                i++;
            while (x < data[j])
                j--;
            if (i <= j) {
                long temp = data[i];
                data[i] = data[j];
                data[j] = temp;
                i++;
                j--;
            }
        } while (i <= j);
        if (left < j)
            quicksort(data, left, j);
        if (i < right)
            quicksort(data, i, right);
    }

    public static void quicksort(final double[] data) {
        quicksort(data, 0, data.length - 1);
    }

    public static void quicksort(final double[] data, final int left, final int right) {
        if (data == null || data.length < 2)
            return;
        int i = left, j = right;
        double x = data[(left + right) / 2];
        do {
            while (data[i] < x)
                i++;
            while (x < data[j])
                j--;
            if (i <= j) {
                double temp = data[i];
                data[i] = data[j];
                data[j] = temp;
                i++;
                j--;
            }
        } while (i <= j);
        if (left < j)
            quicksort(data, left, j);
        if (i < right)
            quicksort(data, i, right);
    }

    public static void quicksort(final float[] data) {
        quicksort(data, 0, data.length - 1);
    }

    public static void quicksort(final float[] data, final int left, final int right) {
        if (data == null || data.length < 2)
            return;
        int i = left, j = right;
        float x = data[(left + right) / 2];
        do {
            while (data[i] < x)
                i++;
            while (x < data[j])
                j--;
            if (i <= j) {
                float temp = data[i];
                data[i] = data[j];
                data[j] = temp;
                i++;
                j--;
            }
        } while (i <= j);
        if (left < j)
            quicksort(data, left, j);
        if (i < right)
            quicksort(data, i, right);
    }

    public static void quicksort(final double[] data, final int[] sortAlso, final int left, final int right) {
        if (data == null || data.length < 2)
            return;
        int i = left, j = right;
        double x = data[(left + right) / 2];
        do {
            while (data[i] < x)
                i++;
            while (x < data[j])
                j--;
            if (i <= j) {
                double temp = data[i];
                data[i] = data[j];
                data[j] = temp;

                int temp2 = sortAlso[i];
                sortAlso[i] = sortAlso[j];
                sortAlso[j] = temp2;

                i++;
                j--;
            }
        } while (i <= j);
        if (left < j)
            quicksort(data, sortAlso, left, j);
        if (i < right)
            quicksort(data, sortAlso, i, right);
    }
}

Related

  1. quicksort(double lista1[], int lista2[], int izq, int der)
  2. quickSort(double[] array, int low, int high)
  3. quickSort(double[] array, int[] idx, int from, int to)
  4. quicksort(double[] main, int[] index)
  5. quicksort(final double[] array, final int[] index)
  6. quicksort(float[] a, int[] index, int left, int right)
  7. quickSort(int[] a)
  8. quickSort(int[] a, int start, int end)
  9. quickSort(int[] a, int start, int end, int[] p)