also I dont think that for case 0 we do not need to have one ++. I guess it fails for this example
2200101 On Mon, Jan 2, 2012 at 5:36 PM, Arun Vishwanathan <[email protected]>wrote: > @utkarsh: in yr code it shud be two-- after the swap function and not > before for case 2 > > > On Thu, Nov 10, 2011 at 1:25 PM, UTKARSH SRIVASTAV < > [email protected]> wrote: > >> >> >> sorry it was incomplete >> >> >> On Fri, Nov 11, 2011 at 2:53 AM, UTKARSH SRIVASTAV < >> [email protected]> wrote: >> one = zero = 0; >> two = n-1; //n is length of string >> >> while(two>=one) >> { >> switch(a[one]) >> { >> case '0' : swap(a[zero],z[one]); >> one++;zero++;break; >> case '1' : one++; >> break; >> case '2' : two--; >> swap(a[one],a[two]); >> >> } >> } >> >> >> >>> >>> On Mon, Oct 24, 2011 at 9:50 PM, praveen raj <[email protected]>wrote: >>> >>>> This can be done in O(n).. >>>> >>>> first shift all the 2's to the right side in O(n)... >>>> >>>> then again shift 1to the right shift b efore 2's......... in O(n)... >>>> >>>> >>>> With regards, >>>> >>>> Praveen Raj >>>> DCE-IT 3rd yr >>>> 9999735993 >>>> [email protected] >>>> >>>> >>>> >>>> >>>> On Mon, Sep 26, 2011 at 6:23 PM, Naren s <[email protected]> wrote: >>>> >>>>> dutch national flag problem..search in wiki...classical. >>>>> >>>>> On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI <[email protected]>wrote: >>>>> >>>>>> You are given a string (consisting of 0's, 1's or 2's) where 0 >>>>>> represents a blue ball, 1 a >>>>>> red ball, and 2 a black ball. Using only swap operations (counting >>>>>> sort not allowed) >>>>>> rearrange the string such that all blue balls are together on one >>>>>> side, followed by all red >>>>>> balls, and then all black balls. You can iterate through the string >>>>>> only once. >>>>>> Eg 102112011 should produce 001111122 >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Algorithm Geeks" group. >>>>>> To post to this group, send email to [email protected]. >>>>>> To unsubscribe from this group, send email to >>>>>> [email protected]. >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> *Narayanan S,* >>>>> B.E., C.S.E., (final year), >>>>> College Of Engineering Guindy, >>>>> Anna University, >>>>> Chennai-25. >>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]. >>>>> 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 [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>> >>> >>> >>> -- >>> *UTKARSH SRIVASTAV >>> CSE-3 >>> B-Tech 3rd Year >>> @MNNIT ALLAHABAD* >>> >>> >>> >> >> >> -- >> *UTKARSH SRIVASTAV >> CSE-3 >> B-Tech 3rd Year >> @MNNIT ALLAHABAD* >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > "People often say that motivation doesn't last. Well, neither does > bathing - that's why we recommend it daily." > > -- "People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily." -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
