scan the array from both the ends..i.e use two pointers to scan the array..
left pointer points at the beginning and right one one at the end..
left pointer can be used to find whether an element is even or not until it
reaches end while right pointer can be used to find whthr a no is odd until
it reaches the starting of the array..
for (i=0 until i+ a[].length){
if (*leftptr % 2 == 0)
A2[i] = *leftptr ;
else
leftptr++;
if (*rtptr % 2 == 0)
A2[i+a[].length-1] = *rtptr ;
else
rtptr--;
}
On Thu, Jul 21, 2011 at 11:32 PM, UMESH KUMAR <[email protected]>wrote:
> Hi
> Given an array A[], write a function to separate even and odd numbers
> (i.e., put all even numbers first than odd numbers) and stability is also
> maintain for the elements in the Array.
>
> Eg.
> input:
>
> A[] = {12, 34, 45, 9, 8, 90, 3}
>
> output:
> A[] = {12, 34, 8, 90, 45, 9, 3}**
>
>
>
>
> Thanks
>
> --
> 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.