The instructions to answer my question are below in bulletpo
The instructions to answer my question are below in bulletpoints, and write the code in Java, thank you.
Merge Two Arrays The array temp contains two sorted halves: index 0-9 and index 10-19 Write a while loop to merge them into the array sortedarr Write an if-else to decide which item to move to the array sortedarr When the loop completes two loops are needed to move any remaining items Do not declare any variables or initialize the arrays, that is done for you. Implement the instructions above by placing your Code here: half1 = 0;//start of the 1st half of array half2 = 10;//start of the second half of array mergeoff = 0;//variable to track offset in sorted array while () {if () {} else {}} while () {//loop to merge any remainder in first half} While () {//loop to merge any remainder in second half}Solution
half1 = 0;
half2 = 10;
mergeoff = 0;
while(half1<10 && half2<20)
{
if(temp[half1]<=temp[half2])
{
sortedarr[mergeoff] = temp[half1];
half1++;
}
else
{
sortedarr[mergeoff] = temp[half2];
half2++;
}
mergeoff++;
}
while(half1<10)
{
sortedarr[mergeoff] = temp[half1];
half1++;
mergeoff++;
}
while(half2<20)
{
sortedarr[mergeoff] = temp[half2];
half2++;
mergeoff++;
}
