code: protected static int partition(Instances insts, int[] index, int attidx, int l, int r) {
      
      double pivot = insts.instance(index[(l + r) / 2]).value(attidx);
      int help;
  
      while (l < r) {
        while ((insts.instance(index[l]).value(attidx) < pivot) && (l < r)) {
          l++;
        }
        while ((insts.instance(index[r]).value(attidx) > pivot) && (l < r)) {
          r--;
        }
        if (l < r) {
          help = index[l];
          index[l] = index[r];
          index[r] = help;
          l++;
          r--;
        }
      }
      if ((l == r) && (insts.instance(index[r]).value(attidx) > pivot)) {
        r--;
      } 
  
      return r;
    }
docs: Partitions the instances around a pivot. Used by quicksort and
  kthSmallestValue.
  
  @param insts	The instances on which the tree is (or is
  to be) built.
  @param index The master index array containing indices
  of the instances.
  @param attidx The attribution/dimension based on which
  the instances should be partitioned.
  @param l	The begining index of the portion of master index
  array that should be partitioned.
  @param r	The end index of the portion of master index array
  that should be partitioned.
  @return the index of the middle element