Java Array Sort sortDescending(T[] a, int fromIndex, int toIndex)

Here you can find the source of sortDescending(T[] a, int fromIndex, int toIndex)

Description

sort Descending

License

Apache License

Parameter

Parameter Description
a the array to be sorted
fromIndex the index of the first element (inclusive) to be sorted
toIndex the index of the last element (exclusive) to be sorted

Return

the specified array

Declaration

public static <T> T[] sortDescending(T[] a, int fromIndex, int toIndex) 

Method Source Code


//package com.java2s;
/*//from  w ww. java  2s .  co  m
 * Copyright (c) 2008 Kasper Nielsen.
 *
 * 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.
 */

import java.util.Arrays;

public class Main {
    /**
     * @param a
     *            the array to be sorted
     * @param fromIndex
     *            the index of the first element (inclusive) to be sorted
     * @param toIndex
     *            the index of the last element (exclusive) to be sorted
     * @return the specified array
     */
    public static <T> T[] sortDescending(T[] a, int fromIndex, int toIndex) {
        Arrays.sort(a, fromIndex, toIndex);
        toIndex--;
        while (fromIndex < toIndex) {
            T t = a[fromIndex];
            a[fromIndex++] = a[toIndex];
            a[toIndex--] = t;
        }
        return a;
    }
}

Related

  1. sortByString(Object[] array)
  2. sortByValue(int start, int end, double[] values, int[] indexes)
  3. sortByValueStable(int start, int end, double[] values, int[] indexes)
  4. sortCompare(String[] valuesOne, String[] valuesTwo)
  5. sortDesc(long[] keys, int[] values)
  6. SortDoubleDimensionArray(String StrArr[][])
  7. sorted(int[] array)
  8. sortedArraysEqual(Object[] arr1, Object[] arr2)
  9. sortedCopyOf(final int[] array)