Essentially :
1. In pass 1, go through the array and count the number of 1's, 2's and 3's.
2. pass 2 : copy to array the appropriate count of 1's followed by 2's and 3's
//Assume that the array has only 1, 2, or 3 as values
public void sortInPlace(int[] a) {
int oneCount = 0;
int twoCount = 0;
int threeCount = 0;
for(int i = 0; i 0) {
a[i] = 1;
--oneCount;
} else if(twoCount > 0) {
a[i] = 2;
--twoCount;
} else {
a[i] = 3;
--threeCount;
}
}
} //End of the method sortInplace