Sort an Array of 0s and 1s

How would you sort an array that consists of only zeros and ones in only one pass?
Answer:


Use Quick Sort :

0 1 1 1 0 0 1 0 0 1
^ ^ ^
up pivot down

Quick sort will do this in one pass.

Count Sort will do this in two passes.


No comments: