Java Array Sort sort5(Long[] data)

Here you can find the source of sort5(Long[] data)

Description

sort

License

Open Source License

Declaration

public static Long[] sort5(Long[] data) 

Method Source Code

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

public class Main {
    public static Long[] sort5(Long[] data) {
        long[] temp = new long[] { data[0] != null ? data[0] : -1, data[1] != null ? data[1] : -1,
                data[2] != null ? data[2] : -1, data[3] != null ? data[3] : -1, data[4] != null ? data[4] : -1, };

        sort5(temp);//from   ww w .ja  v  a 2 s .  c  om

        return new Long[] { temp[0] < 0 ? null : temp[0], temp[1] < 0 ? null : temp[1],
                temp[2] < 0 ? null : temp[2], temp[3] < 0 ? null : temp[3], temp[4] < 0 ? null : temp[4], };
    }

    public static void sort5(long[] data) {
        // from http://stackoverflow.com/questions/32172144/fastest-way-to-sort-10-numbers-numbers-are-32-bit
        long swap;
        if (data[0] > data[3]) {
            swap = data[0];
            data[0] = data[3];
            data[3] = swap;
        }
        if (data[1] > data[4]) {
            swap = data[1];
            data[1] = data[4];
            data[4] = swap;
        }
        if (data[0] > data[2]) {
            swap = data[0];
            data[0] = data[2];
            data[2] = swap;
        }
        if (data[0] > data[1]) {
            swap = data[0];
            data[0] = data[1];
            data[1] = swap;
        }
        if (data[2] > data[4]) {
            swap = data[2];
            data[2] = data[4];
            data[4] = swap;
        }
        if (data[1] > data[2]) {
            swap = data[1];
            data[1] = data[2];
            data[2] = swap;
        }
        if (data[1] > data[3]) {
            swap = data[1];
            data[1] = data[3];
            data[3] = swap;
        }
        if (data[2] > data[3]) {
            swap = data[2];
            data[2] = data[3];
            data[3] = swap;
        }
        if (data[3] > data[4]) {
            swap = data[3];
            data[3] = data[4];
            data[4] = swap;
        }
    }
}

Related

  1. sort1(long x[], int off, int len)
  2. sort2(double v[], int v2[], int left, int right)
  3. sort2(double[] arr, double[] brr)
  4. sort3(String[] a, int x, int y, int z)
  5. sort3(String[] arr, float[] brr)
  6. sortableBytesToInt(byte[] encoded, int offset)
  7. sortAccording(float[] ary, Integer[] sortOrder)
  8. sortAccording2(int[] ary, Integer[] sortOrder)
  9. sortAlleleCount(int[] count)