My question is asking:
f u n c ti o n combinedArray = combine2Arrays( a r ray1 , a r r a y 2 )
Where: e array1 is a 1 by n sorted double array, and array2 is a 1 by m sorted double array.
How do I define these variables? Thanks a lot.
Also, how to define combine2Arrays too?
The whole question looks like this:
In this exercise, you will implement the merge sort algorithm to sort a unsorted 1-d double array.
1. Write a nested function called combine2Arrays with the following function signature:
1 f u n c ti o n combinedArray = combine2Arrays( a r ray1 , a r r a y 2 )
where array1 is a 1 by n sorted double array, and array2 is a 1 by m sorted double array, your function combine2Arrays should return combinedArray, the combined and sorted array of array1 and array2.
For example, combine2Arrays([1, 3, 5], [2, 4]) should return [1, 2, 3, 4, 5].
2. Write a function called mergeSort with the following function signature:
1 f u n c ti o n s o r t e dA r r a y = mergeSort ( doubleArray )
where doubleArray is a 1 by N unordered double array to be sorted, sortedArray is the sorted array of doubleArray. Merge sort splits the array into two sub-arrays, recursively sorts the two sub-arrays, and then combines the two sorted sub-arrays. For example, merge sort first splits the array [10, 8, 3, 8, 6, 1] into 2 sub-arrays: [10, 8, 3] and [8, 6, 1]. It then sorts the 2 sub-arrays recursively and gets [3, 8, 10] and [1, 6, 8]. Finally, it combines these two sorted sub-arrays and return [1, 3, 6, 8, 8, 10]. Use the nested function combine2Arrays you developed to combine the two sorted sub-arrays.