Thank you, I understood the question wrong. I thought if the # of 0's or #1's exceeded each other, the whole array would be untouched. So i couldn't solve it in one pass.
On 13 Kasım, 16:15, 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) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
