Yes, it is possible in one pass without extra memory, I think this is a CLRS exercise problem.
It is possible in one pass without using extra memory. Keep the 0's at left and 2's at right and scan the middle portion from left to right and if you see 0 keep at left side and if you see 2 keep it right side, what is left in the middle is the 1's. Keep track of 1's the tricky part and have a index at start of 1's. I think it is possible, I have a tested code, I will post, but you can try once. Thanks, Sathaiah Dontula On Mon, Aug 23, 2010 at 12:10 PM, Manjunath Manohar < manjunath.n...@gmail.com> wrote: > is it possible to do without any extra space... > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.