Java Array Sort sortArrayAndReturnIndex(double[] p, String t)

Here you can find the source of sortArrayAndReturnIndex(double[] p, String t)

Description

sort Array And Return Index

License

Open Source License

Declaration

public static int[] sortArrayAndReturnIndex(double[] p, String t) 

Method Source Code

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

public class Main {
    public static int[] sortArrayAndReturnIndex(double[] p, String t) {
        int[] ret = new int[p.length];
        for (int i = 0; i < ret.length; i++) {
            ret[i] = i;//from   ww  w .  j a va  2 s .c o m
        }
        if (t.equals("desc")) {
            //buyukten kucuge sirala
            double temp = p[0];
            int q = 0;
            for (int i = 0; i < p.length; i++) {
                for (int j = i; j < p.length; j++) {
                    if (p[j] > p[i]) {
                        temp = p[i];
                        p[i] = p[j];
                        p[j] = temp;

                        q = ret[i];
                        ret[i] = ret[j];
                        ret[j] = q;
                    }
                }
            }
        }
        if (t.equals("asc")) {
            //kucukten buyuge sirala
            double temp = 0;
            int q = 0;
            for (int i = 0; i < p.length; i++) {
                for (int j = i; j < p.length; j++) {
                    if (p[j] < p[i]) {
                        temp = p[i];
                        p[i] = p[j];
                        p[j] = temp;

                        q = ret[i];
                        ret[i] = ret[j];
                        ret[j] = q;
                    }
                }
            }
        }
        return ret;
    }
}

Related

  1. sortAlleleCount(int[] count)
  2. SortAndConcatenateStringArray(String StrArray[], String Separator)
  3. sortArray(double[] array)
  4. sortArray(int[] a)
  5. sortArray(int[] array)
  6. sortByFirst(int[] array1, int[] array2)
  7. sortByIndex(final double[] data, int size)
  8. sortByIndex(int start, int end, int[] indexes, double[] values)
  9. sortByIndex(int start, int end, int[] indexes, double[] values)