Java Quick Sort quickSortReverse(String[] sortedCollection, int left, int right)

Here you can find the source of quickSortReverse(String[] sortedCollection, int left, int right)

Description

Sort the strings in the given collection in reverse alphabetical order.

License

Open Source License

Declaration

private static void quickSortReverse(String[] sortedCollection, int left, int right) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright ? 2000, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from   www  .j  a  v  a2 s.  c  o  m*/
 * IBM Corporation - initial API and implementation
 *
 *******************************************************************************/

public class Main {
    /**
     * Sort the strings in the given collection in reverse alphabetical order.
     */
    private static void quickSortReverse(String[] sortedCollection, int left, int right) {
        int original_left = left;
        int original_right = right;
        String mid = sortedCollection[(left + right) / 2];
        do {
            while (sortedCollection[left].compareTo(mid) > 0) {
                left++;
            }
            while (mid.compareTo(sortedCollection[right]) > 0) {
                right--;
            }
            if (left <= right) {
                String tmp = sortedCollection[left];
                sortedCollection[left] = sortedCollection[right];
                sortedCollection[right] = tmp;
                left++;
                right--;
            }
        } while (left <= right);
        if (original_left < right) {
            quickSortReverse(sortedCollection, original_left, right);
        }
        if (left < original_right) {
            quickSortReverse(sortedCollection, left, original_right);
        }
    }
}

Related

  1. quickSort1(double array[], int low, int n)
  2. quickSort1(int target[], int fromIndex, int length, int[] coSort)
  3. quickSort2(int target[], int fromIndex, int length, int[] coSort)
  4. quickSortInt(int[] data, int[] dataIdx, int len)
  5. quickSortMaxToMin(int a[], int lo0, int hi0)
  6. quickSortReverso(double[] arr, int esquerda, int direita)
  7. quickSortStringArray(String array[], int lo0, int hi0)