@Dave, Ya. You are right. I think i overlooked your solution. The step 'set the even position to 0...' sounded like, setting 0 and 1 directly :-)
Thanks, Vikram On 11/13/07, Dave <[EMAIL PROTECTED]> wrote: > > > No. At step 6, we have found a 1 in an even spot and a 0 in an odd > spot, so we switch them. Switching a 1 and a 0 simply means storing 0 > where the 1 was and storing 1 where the 0 was; there is no need to use > the usual code to interchange two values. > > Dave > > On Nov 13, 8:37 am, "Vikram Venkatesan" <[EMAIL PROTECTED]> > wrote: > > @Dave, > > >>*Otherwise, set the even position to 0 and the odd position to 1.* > > I think your solution might be inserting 0's and 1's into the array > from > > nowhere (thus filling the whole array with alternating 0's and 1's up to > the > > given size !). The question is to re-arrange existing elements in the > array. > > > > -Vikram > > > > On 11/13/07, Dave <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > The following algorithm examine the contents of each element of the > > > array at most once. > > > > > 1. Start with the first even position and the first odd position. > > > 2. Search forward through the even positions until you reach the end > > > of the array or find a 1, whichever comes first. > > > 3. Search forward through the odd positions until you reach the end of > > > the array or find a 0, whichever comes first. > > > 4. If you reached the end of the array in either of the above > > > searches, you are finished. > > > 5. Otherwise, set the even position to 0 and the odd position to 1. > > > 6. Repeat steps 2-6. > > > > > Dave > > > > > On Nov 13, 7:39 am, geekko <[EMAIL PROTECTED]> wrote: > > > > you are given an array of integers containing only 0s and 1s. You > have > > > > to place all the 0s in even positions and 1s in odd position. And if > > > > suppose, no. of 0s exceeds no. of 1s or vice versa keep them > > > > untouched. Do in ONE PASS without taking extra memory.(modify array > in > > > > place)- Hide quoted text - > > > > - Show quoted text - > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---