Here you can find the source of sortReversed(final int[] a)
Parameter | Description |
---|---|
a | array to be reverse-sorted |
public static void sortReversed(final int[] a)
//package com.java2s; //License from project: Apache License import java.util.Arrays; public class Main { /**/*from w ww .jav a2 s . com*/ * Sorts the specified int array in reversed order. * * @param a array to be reverse-sorted */ public static void sortReversed(final int[] a) { if (a.length <= 1) return; // Sorted as it is; also empty array might cause trouble (last = -1 /2) // 1. Sort Arrays.sort(a); // 1. Reverse final int last = a.length - 1; for (int i = last / 2; i >= 0; i--) { // Swap final int temp = a[i]; a[i] = a[last - i]; a[last - i] = temp; } } }