Java Quick Sort quickSortReverso(double[] arr, int esquerda, int direita)

Here you can find the source of quickSortReverso(double[] arr, int esquerda, int direita)

Description

quick Sort Reverso

License

Apache License

Declaration

public static double[] quickSortReverso(double[] arr, int esquerda, int direita) 

Method Source Code

//package com.java2s;
/*//from w ww  .ja va2 s .  com
 * Copyright 2016 JoinFaces.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static double[] quickSortReverso(double[] arr, int esquerda, int direita) {

        double[] vector = new double[arr.length];
        if (arr == null || arr.length == 0) {
            return null;
        }

        if (esquerda >= direita) {
            return null;
        }

        double pivot = arr[esquerda + (direita - esquerda) / 2];
        int i = esquerda;
        int j = direita;
        double tmp;

        while (i <= j) {
            while (arr[i] < pivot) {
                i++;
            }
            while (arr[j] > pivot) {
                j--;
            }
            if (i <= j) {
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
                i++;
                j--;
            }
        }
        if (esquerda < j) {
            quickSortReverso(arr, esquerda, j);
        }

        if (direita > i) {
            quickSortReverso(arr, i, direita);
        }

        vector = inverter(arr);

        return vector;
    }

    public static double[] inverter(double[] vector) {
        double[] vetorInverso = new double[vector.length];
        int j = vector.length - 1;
        for (int i = 0; i < vetorInverso.length; i++) {
            vetorInverso[i] = vector[j];
            j--;
        }

        return vetorInverso;
    }
}

Related

  1. quickSort1(int target[], int fromIndex, int length, int[] coSort)
  2. quickSort2(int target[], int fromIndex, int length, int[] coSort)
  3. quickSortInt(int[] data, int[] dataIdx, int len)
  4. quickSortMaxToMin(int a[], int lo0, int hi0)
  5. quickSortReverse(String[] sortedCollection, int left, int right)
  6. quickSortStringArray(String array[], int lo0, int hi0)