Selects a single pivot (median of three) and partitions the array into three regions in one scan: less than, equal to, and greater than the pivot. Only the non-equal regions recurse.
Grouping equal elements costs O(n) per partition but eliminates all further work on them. In the all-equal case it finishes in a single O(n) scan with no recursive calls. Unlike Dual-Pivot, which uses two pivots to optimise random-data throughput, 3-way targets duplicate-heavy data with one pivot.