Sorts an array of three distinct values (such as 0s, 1s, and 2s) in a single pass with low, mid, and high pointers.