Consider two array a[] and b[].
Suppose Number of elements  in  a[] are n and number of elements in b[] are
m. a[] can accomodate m+n elements.

MergeInPlace(int a[], int b[],int n,int m)
{
   int i=n-1;
  int j=m-1;
  int k=n+m-1;
  while(i>0 && j>0)
   {
     if(a[i]>=b[j])
         a[k--]=a[i--]
     else
         a[k--]=b[j--]
    }

    while(j>0)
     {
       a[k--]=b[j--]
     }
}


On Thu, Aug 4, 2011 at 10:46 PM, Kamakshii Aggarwal
<[email protected]>wrote:

>
> how can  two sorted arrays be merged inplace?
> --
> Regards,
> Kamakshi
> [email protected]
>
> --
> 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.
>



-- 
Regards :
ROHIT JALAN
B.E. Graduate,
Computer Science Department,
RVCE, Bangalore

-- 
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.

Reply via email to