Java Array Sort sortReverseOrder(String[] strings)

Here you can find the source of sortReverseOrder(String[] strings)

Description

Sorts an array of strings in place using quicksort in reverse alphabetical order.

License

Open Source License

Declaration

public static void sortReverseOrder(String[] strings) 

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 w ww.  j  av a2  s  .  co  m*/
 * IBM Corporation - initial API and implementation
 *
 *******************************************************************************/

public class Main {
    /**
     * Sorts an array of strings in place using quicksort
     * in reverse alphabetical order.
     */
    public static void sortReverseOrder(String[] strings) {
        if (strings.length > 1)
            quickSortReverse(strings, 0, strings.length - 1);
    }

    /**
     * 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. sortPerm(final int[] w)
  2. sortPermutation(final int[] A)
  3. sortPixels(double[] data, int numPixel)
  4. sortPopup(Integer[] integers)
  5. sortRetain(long[] a)
  6. sortStringArray(String array[], boolean inplace)
  7. sortStringArray(String[] array)
  8. sortStringArray(String[] array)
  9. sortStringArray(String[] source)