Possible Duplicate:
Reordering of array elements
Interview test - rearrange the array
I have an array where three semantic elements (a,b,c) are stored in the form:
[a][b][c][a][b][c][a][b][c]...
This means that a b and c are not actual values. The first a might be 10, the second 1, the third 25, and so on. a b and c says that the program will give all indices where you see an "a" a certain semantic meaning, the same for b and c.
I want to reorder so it has the form:
[a][a][a]...[b][b][b]...[c][c][c]....
Is there a way to do this "in-place", meaning without the usage of a temporary "buffer" array?
An example with values:
Starting array:
[11][5][3][284][123123][841823][0][11][22]
I need to reorder it to:
[11][284][0][5][123123][11][3][841823][22]