86,89d85
<     
<     if (compare(lo, mid) > 0) {
<       swap(lo, mid);
<     }
91c87,93
<     if (compare(mid, hi) > 0) {
---
>     // see http://en.wikipedia.org/wiki/Quicksort#inplace
>     // leaving the following triple-swap to determine possibly better pivot,
>     // but swap pivot to end so that it's out of the way
>     if (compare(lo, hi) > 0) {
>       swap(lo, hi);
>     }
>     if (compare(mid, hi) < 0) {
93,94c95,96
<       if (compare(lo, mid) > 0) {
<         swap(lo, mid);
---
>       if (compare(lo, hi) > 0) {
>         swap(lo, hi);
97,104d98
<     
<     int left = lo + 1;
<     int right = hi - 1;
< 
<     setPivot(mid);
<     for (;;) {
<       while (comparePivot(right) < 0)
<         --right;
106,114c100,108
<       while (left < right && comparePivot(left) >= 0)
<         ++left;
< 
<       if (left < right) {
<         swap(left, right);
<         --right;
<       } else {
<         break;
<       }
---
>     setPivot(hi);
>     
>     int left = lo;
>     int right= lo;
>     
>     for (; right < hi; right++) {
>       if (comparePivot(right) > 0) // smaller than pivot found
>         // swap it to larger-equal-to-pivot element before or itself
>         swap(left++, right);
115a110,111
>     // move pivot to correct position
>     swap(left, hi);
117c113
<     quickSort(lo, left, maxDepth);
---
>     quickSort(lo, left - 1, maxDepth);
