public void sortFromTo(int from,int to){
  final int widthThreshold=10000;
  if (size == 0)   return;
  checkRangeFromTo(from,to,size);
  char min=elements[from];
  char max=elements[from];
  char[] theElements=elements;
  for (int i=from + 1; i <= to; ) {
    char elem=theElements[i++];
    if (elem > max)     max=elem;
 else     if (elem < min)     min=elem;
  }
  double N=(double)to - (double)from + 1.0;
  double quickSortEstimate=N * Math.log(N) / 0.6931471805599453;
  double width=(double)max - (double)min + 1.0;
  double countSortEstimate=Math.max(width,N);
  if (width < widthThreshold && countSortEstimate < quickSortEstimate) {
    countSortFromTo(from,to,min,max);
  }
 else {
    quickSortFromTo(from,to);
  }
}

public void sortFromTo ( int from , int to ) { final int widthThreshold = 10000 ; if ( size == 0 ) return ; checkRangeFromTo ( from , to , size ) ; char min = elements [ from ] ; char max = elements [ from ] ; char [ ] theElements = elements ; for ( int i = from + 1 ; i <= to ; ) { char elem = theElements [ i ++ ] ; if ( elem > max ) max = elem ; else if ( elem < min ) min = elem ; } double N = ( double ) to - ( double ) from + 1.0 ; double quickSortEstimate = N * Math . log ( N ) / 0.6931471805599453 ; double width = ( double ) max - ( double ) min + 1.0 ; double countSortEstimate = Math . max ( width , N ) ; if ( width < widthThreshold && countSortEstimate < quickSortEstimate ) { countSortFromTo ( from , to , min , max ) ; } else { quickSortFromTo ( from , to ) ; } }
sorts the specified range of the receiver into ascending order . the sorting algorithm is dynamically chosen according to the characteristics of the data set . currently quicksort and countsort are considered . countsort is not always applicable , but if applicable , it usually outperforms quicksort by a factor of 3 - 4 . < p > best case performance : o ( n ) . < dt > worst case performance : o ( n ^ 2 ) ( a degenerated quicksort ) . < dt > best case space requirements : 0 kb . < dt > worst case space requirements : 40 kb .
