This is one of an interview question which I had recently. I would like to know others perception of approach for this problem.
Question:
Yo
Here is solution that works for an array of int. You can modify it.
int
sort (int [] a) { int pos = 0; for (int i = 1; i < a.length; i++) { if (a[i] == 0 && a[pos] == 1) { swap(a, pos, i); // this makes all 0's go to the left. pos++; } } }