public static void sortByValueStable(int start,int end,double[] values,int[] indexes){
  sortByValue(start,end,values,indexes);
  for (int i=0; i < values.length - 1; i++) {
    double tmp=values[i];
    int len=0;
    while (i + len + 1 < values.length && tmp == values[i + len + 1])     len++;
    if (len > 0) {
      Arrays.sort(indexes,i,i + len + 1);
      i+=len;
    }
  }
}

public static void sortByValueStable ( int start , int end , double [ ] values , int [ ] indexes ) { sortByValue ( start , end , values , indexes ) ; for ( int i = 0 ; i < values . length - 1 ; i ++ ) { double tmp = values [ i ] ; int len = 0 ; while ( i + len + 1 < values . length && tmp == values [ i + len + 1 ] ) len ++ ; if ( len > 0 ) { Arrays . sort ( indexes , i , i + len + 1 ) ; i += len ; } } }
in - place sort of two arrays , only indexes is used for comparison and values of same position are sorted accordingly .
