Sort an array of 0s, 1s, and 2s in one pass, in place —
Dijkstra's Dutch National Flag partition. Three regions grow as mid scans:
0s to the left, 2s to the right, everything unclassified in the middle.
mid only advances after a 0 or 1 swap — after swapping in a 2, the new value at mid is unexamined, so it stays put.