I\'ve made a solution for the Dutch national flag problem already.
But this time, I want to try something more difficult: the Mauritus national flag problem - 4 colours,
This is just like the Dutch national flag problem, but we have four colors. Essentially the same strategy applies. Assume we have (where ^ represents the point being scanned).
RRRRBBB???????????YYYYGGGG
^
and we scan a
So we need to keep track or one more pointer than usual.
We need to keep track of the first blue, the first ?, the last ?, the last Y
In general, the same strategy works for any number of colors, but an increasing numbers of swaps are needed.