Here you can find the source of sortDescending(T[] a, int fromIndex, int toIndex)
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 |
public static <T> T[] sortDescending(T[] a, int fromIndex, int toIndex)
//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; } }