Java Utililty Methods Array Sort

List of utility methods to do Array Sort

Description

The list of methods to do Array Sort are organized into topic(s).

Method

double[]sort(double[] data, boolean desc)
sort
for (int i = 0; i < data.length - 1; i++) {
    for (int j = 0; j < data.length - i - 1; j++) {
        if (desc) {
            if (data[j] < data[j + 1]) {
                double tmp = data[j];
                data[j] = data[j + 1];
                data[j + 1] = tmp;
        } else {
            if (data[j] > data[j + 1]) {
                double tmp = data[j];
                data[j] = data[j + 1];
                data[j + 1] = tmp;
return data;
voidsort(Double[] inArray)
A simple Insertion sort performed on an array of doubles
int idx = 0;
int j;
double x;
for (int i = 1; i < inArray.length; i++) {
    j = i;
    x = inArray[i];
    while ((j > 0) && (inArray[j - 1] > x)) {
        inArray[j] = inArray[j - 1];
...
voidsort(double[] vector, boolean ascending)
sort
Arrays.sort(vector);
if (!ascending) {
    for (int i = 0; i <= (vector.length - 1) / 2; i++) {
        double tmp = vector[i];
        vector[i] = vector[vector.length - i - 1];
        vector[vector.length - i - 1] = tmp;
int[]sort(double[] x)
sort
int[] id = new int[x.length];
boolean[] fid = new boolean[id.length];
int cnt = 0;
for (int i = 0; i < id.length; i++) {
    int mi = 0;
    double min = x[mi];
    for (int j = 0; j < x.length; j++) {
        if (fid[j]) {
...
voidsort(E[] x, int[] w)
sorts x increasingly according to the weights w
assert (x.length == w.length);
applyPermutation(x, sortPerm(w));
double[]sort(final double[] data)
Allocates new array which is sorted version of argument.
final double ret[] = copyOf(data);
Arrays.sort(ret);
return ret;
int[]sort(final int[] data)
sort
return sort(data, true);
voidsort(final long[] primary, final double[] secondary)
sort
boolean tmpSwapped;
final int tmpLimit = Math.min(primary.length, secondary.length) - 1;
do {
    tmpSwapped = false;
    for (int i = 0; i < tmpLimit; i++) {
        if (primary[i] > primary[i + 1]) {
            final long tmpPrimVal = primary[i];
            primary[i] = primary[i + 1];
...
int[]Sort(float cais[])
Sort
int res[] = new int[cais.length];
for (int i = 0; i < res.length; i++)
    res[i] = i;
int i, j, k, inc, n = cais.length;
float v;
inc = 1;
do {
    inc *= 3;
...
voidsort(int v[], int left, int right)
sort
int k, last;
if (left >= right)
    return;
swap(v, left, (left + right) / 2);
last = left;
for (k = left + 1; k <= right; k++)
    if (v[k] < v[left])
        swap(v, ++last, k);
...