public double getNthOrderedValue ( double [ ] array , int n , boolean ascending ) { if ( n > array . length ) { n = array . length ; } int targetindex ; if ( ascending ) { targetindex = n ; } else { targetindex = array . length - n ; } // this value is the value of the numKey-th element return getOrderedValue ( array , targetindex ) ; }
Get the n - th value in the array after sorted