public static <T>void binaryInsertionSort(T[] d,int left,int right,Comparator<T> comp){
  for (int i=left + 1; i <= right; i++) {
    T t=d[i];
    int l=left;
    for (int r=i; l < r; ) {
      int m=(l + r) >>> 1;
      if (comp.compare(t,d[m]) >= 0) {
        l=m + 1;
      }
 else {
        r=m;
      }
    }
    for (int n=i - l; n > 0; ) {
      d[l + n--]=d[l + n];
    }
    d[l]=t;
  }
}

public static < T > void binaryInsertionSort ( T [ ] d , int left , int right , Comparator < T > comp ) { for ( int i = left + 1 ; i <= right ; i ++ ) { T t = d [ i ] ; int l = left ; for ( int r = i ; l < r ; ) { int m = ( l + r ) > > > 1 ; if ( comp . compare ( t , d [ m ] ) >= 0 ) { l = m + 1 ; } else { r = m ; } } for ( int n = i - l ; n > 0 ; ) { d [ l + n -- ] = d [ l + n ] ; } d [ l ] = t ; } }
sort an array using binary insertion sort
