Question: Given an integer array of which both first half and second half are sorted. Write a function to merge the two parts to create one single sorted array
in place [do not use any extra space].
e.g. If input array is [1,3,6,8,-5,-2,3,8] It should be converted to: [-5,-2,1,3,3,6,8,8]
------------------------------------------------------------------------------------------------------
int* SortedArr(int b[],int n)
{
int mid=n/2;
int temp=0;
for(int i=0;i<mid;i++)
{
for(int j=n-1;j>=mid;j--)
{
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
}
}
return b;
}
---------------------------------------------------------
This function will return in sorted array
The main function will be like thisint* SortedArr(int*,int);
void main()
{
int b[8]={1,3,6,8,-5,-2,3,8};
SortedArr(b,8);
printf("\n");
for(int i=0;i<8;i++)
{
printf("%d\n",*(b+i));
}
}