Java Array Sort sortArray(int[] a)

Here you can find the source of sortArray(int[] a)

Description

sort Array

License

Open Source License

Declaration

public static int[] sortArray(int[] a) 

Method Source Code

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

public class Main {
    public static int[] sortArray(int[] a) {
        int[] b = a.clone();
        int t = 0;
        for (int i = 0; i < a.length; i++) {
            for (int j = i; j < a.length; j++) {
                if (b[i] > b[j]) {
                    t = b[i];//w w  w .  ja v a  2s  .  co  m
                    b[i] = b[j];
                    b[j] = t;
                }
            }
        }
        return b;
    }

    public static double[] sortArray(double[] a, int[] index) {
        double[] b = a.clone();
        for (int i = 0; i < a.length; i++) {
            b[i] = a[index[i]];
        }
        return b;
    }

    public static double[] clone(double[] p) {
        double[] ret = new double[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static float[] clone(float[] p) {
        float[] ret = new float[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static int[] clone(int[] p) {
        int[] ret = new int[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static byte[] clone(byte[] p) {
        byte[] ret = new byte[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static char[] clone(char[] p) {
        char[] ret = new char[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static long[] clone(long[] p) {
        long[] ret = new long[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static short[] clone(short[] p) {
        short[] ret = new short[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static String[] clone(String[] p) {
        String[] ret = new String[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static boolean[] clone(boolean[] p) {
        boolean[] ret = new boolean[p.length];
        System.arraycopy(p, 0, ret, 0, p.length);
        return ret;
    }

    public static double[][] clone(double[][] p) {
        double[][] ret = new double[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }

    public static float[][] clone(float[][] p) {
        float[][] ret = new float[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }

    public static int[][] clone(int[][] p) {
        int[][] ret = new int[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }

    public static long[][] clone(long[][] p) {
        long[][] ret = new long[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }

    public static short[][] clone(short[][] p) {
        short[][] ret = new short[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }

    public static byte[][] clone(byte[][] p) {
        byte[][] ret = new byte[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }

    public static boolean[][] clone(boolean[][] p) {
        boolean[][] ret = new boolean[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }

    public static String[][] clone(String[][] p) {
        String[][] ret = new String[p.length][p[0].length];
        int nr = p.length;
        for (int i = 0; i < nr; i++) {
            System.arraycopy(p[i], 0, ret[i], 0, p[0].length);
        }
        return ret;
    }
}

Related

  1. sortAccording(float[] ary, Integer[] sortOrder)
  2. sortAccording2(int[] ary, Integer[] sortOrder)
  3. sortAlleleCount(int[] count)
  4. SortAndConcatenateStringArray(String StrArray[], String Separator)
  5. sortArray(double[] array)
  6. sortArray(int[] array)
  7. sortArrayAndReturnIndex(double[] p, String t)
  8. sortByFirst(int[] array1, int[] array2)
  9. sortByIndex(final double[] data, int size)