private int partition(ObservableArray tab, int lo, int hi)
    {
        int middle = lo;
        int i = lo+1;
        int j = hi;
        
        while(true)
        {
            while(tab.Compare(i, middle) <= 0 && i<hi)
            {
                i++;
            }
            while(tab.Compare(j, middle) >= 0 && j>lo)
            {
                j--;
            }
            if(i<j)
            {
                tab.exchange(i, j);
            }
            else
            {
                break;
            }
        }
        tab.exchange(middle, j);
        return j;
    }