public static int[] stableSort(double[] array){
  int[] index=new int[array.length];
  int[] newIndex=new int[array.length];
  int[] helpIndex;
  int numEqual;
  array=(double[])array.clone();
  for (int i=0; i < index.length; i++) {
    index[i]=i;
    if (Double.isNaN(array[i])) {
      array[i]=Double.MAX_VALUE;
    }
  }
  quickSort(array,index,0,array.length - 1);
  int i=0;
  while (i < index.length) {
    numEqual=1;
    for (int j=i + 1; ((j < index.length) && Utils.eq(array[index[i]],array[index[j]])); j++)     numEqual++;
    if (numEqual > 1) {
      helpIndex=new int[numEqual];
      for (int j=0; j < numEqual; j++)       helpIndex[j]=i + j;
      quickSort(index,helpIndex,0,numEqual - 1);
      for (int j=0; j < numEqual; j++)       newIndex[i + j]=index[helpIndex[j]];
      i+=numEqual;
    }
 else {
      newIndex[i]=index[i];
      i++;
    }
  }
  return newIndex;
}

public static int [ ] stableSort ( double [ ] array ) { int [ ] index = new int [ array . length ] ; int [ ] newIndex = new int [ array . length ] ; int [ ] helpIndex ; int numEqual ; array = ( double [ ] ) array . clone ( ) ; for ( int i = 0 ; i < index . length ; i ++ ) { index [ i ] = i ; if ( Double . isNaN ( array [ i ] ) ) { array [ i ] = Double . MAX_VALUE ; } } quickSort ( array , index , 0 , array . length - 1 ) ; int i = 0 ; while ( i < index . length ) { numEqual = 1 ; for ( int j = i + 1 ; ( ( j < index . length ) && Utils . eq ( array [ index [ i ] ] , array [ index [ j ] ] ) ) ; j ++ ) numEqual ++ ; if ( numEqual > 1 ) { helpIndex = new int [ numEqual ] ; for ( int j = 0 ; j < numEqual ; j ++ ) helpIndex [ j ] = i + j ; quickSort ( index , helpIndex , 0 , numEqual - 1 ) ; for ( int j = 0 ; j < numEqual ; j ++ ) newIndex [ i + j ] = index [ helpIndex [ j ] ] ; i += numEqual ; } else { newIndex [ i ] = index [ i ] ; i ++ ; } } return newIndex ; }
sorts a given array of doubles in ascending order and returns an array of integers with the positions of the elements of the original array in the sorted array . the sort is stable ( equal elements remain in their original order . ) occurrences of double . nan are treated as double . max_value
