Java Array Sort sort(final int[] data)

Here you can find the source of sort(final int[] data)

Description

sort

License

Open Source License

Declaration

public static int[] sort(final int[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    public static int[] sort(final int[] data) {
        return sort(data, true);
    }/* www  .  ja  va 2 s .com*/

    public static int[] sort(final int[] data, boolean ascending) {
        int[] sortedData = data.clone();
        Arrays.sort(sortedData);
        if (!ascending) {
            sortedData = reverse(sortedData);
        }
        return sortedData;
    }

    public static double[] sort(final double[] data) {
        return sort(data, true);
    }

    public static double[] sort(final double[] data, boolean ascending) {
        double[] sortedData = data.clone();
        Arrays.sort(sortedData);
        if (!ascending) {
            sortedData = reverse(sortedData);
        }
        return sortedData;
    }

    public static int[] reverse(final int[] data) {
        int[] reverseData = new int[data.length];
        for (int i = 0, j = data.length - 1; i < data.length; i++, j--) {
            reverseData[i] = data[j];
        }
        return reverseData;
    }

    public static double[] reverse(final double[] data) {
        double[] reverseData = new double[data.length];
        for (int i = 0, j = data.length - 1; i < data.length; i++, j--) {
            reverseData[i] = data[j];
        }
        return reverseData;
    }
}

Related

  1. sort(Double[] inArray)
  2. sort(double[] vector, boolean ascending)
  3. sort(double[] x)
  4. sort(E[] x, int[] w)
  5. sort(final double[] data)
  6. sort(final long[] primary, final double[] secondary)
  7. Sort(float cais[])
  8. sort(int v[], int left, int right)
  9. sort(int values[])