Apex › Storage & databases

Dutch national flag

Dijkstra's one-pass, in-place sort of an array of three values (red/white/blue) using three pointers that carve four regions. Look at the middle pointer: a 0 swaps down, a 2 swaps up, a 1 stays — and the unknown zone shrinks to nothing. It's the partition step of 3-way quicksort, which is what keeps quicksort fast on duplicate-heavy data. Step through and watch the regions form.

More in Storage & databases