What is the C code for mergeing two unsorted arrays without using a 3rd array. Eg array1={1,3,5,7} array2={2,4,6} Output should be array1={1,2,3,4,5,6,7}.
This is the code i have written.But this doesnt work if the number of array elements are same in both arrays.kindly help me in fixing this bug.
void merge(int a[],int b[],int ele1,int ele2)
{
int i,j,k,ele3;
ele3=ele1+ele2;
for(i=1,k=0;k<ele2;i=i+2)
{
j=ele1;
while(j>=i)
{
a[j]=a[j-1];
j--;
}
a[j+1]=b[k];
k++;ele1++;
}
for(i=0;i<ele3;i++)
printf("%d ",a[i]);
}
main()
{
int a[]={1,3,5},b[]={2,4},ele1,ele2;
ele1=sizeof(a)/sizeof(a[0]); ele2=sizeof(b)/sizeof(b[0]);
merge(a,b,ele1,ele2);
}