private static void insertionSort(int[] data, final int start, final int end, IntComparator comp) {
    // Classic insertion sort.
    for(int i = start + 1; i < end; i++) {
      final int cur = data[i];
      int j = i - 1;
      while(j >= start) {
        final int pre = data[j];
        if(comp.compare(cur, pre) >= 0) {
          break;
        }
        data[j + 1] = pre;
        --j;
      }
      data[j + 1] = cur;
    }
  }
private static void insertionSort ( int [ ] data , final int start , final int end , IntComparator comp ) { for ( int i = start + 1 ; i < end ; i ++ ) { final int cur = data [ i ] ; int j = i - 1 ; while ( j >= start ) { final int pre = data [ j ] ; if ( comp . compare ( cur , pre ) >= 0 ) { break ; } data [ j + 1 ] = pre ; -- j ; } data [ j + 1 ] = cur ; } }
Insertion sort, for short arrays.

@param data Data to sort
@param start First index
@param end Last index (exclusive!)
@param comp Comparator