Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Instructions: For program 7, you will merge two arrays into one array that is in ascending order. You may assume that both individual arrays are
Instructions: For program 7, you will merge two arrays into one array that is in ascending order. You may assume that both individual arrays are in ascending order. Consider the two following examples: Example Array 1 Array 2 26 39 44 585972 5 27 42 43 60 61 62 Merged Array 26 2742 4344 58 59 6061 62 72 Example 2: Array 1 Array 2 10 11 12 Merged Array 4 6 7 8 910 1112 Algorithm: Download the starting file mergeArrays.m from Blackboard, as well as the 4 input files: array1a.txt, array2a.txt, array1b.txt, and array2b.txt. Analyze the code in mergeArrays. You are being asked to add code to the commented sections as follows: 1. 2. Populate the second array, similar to how the first array is populated Traverse both arrays using a while loop until either one of the arrays has been entirely traversed (i.e consider the length of each of the arrays). In the above examples, Example 1 will completely traverse array 2 and only partially traverse array 1. In example 2, array 1 will be completely traversed and array 2 will only partially be traversed. You must consider the following Use three variables to traverse the indexes in each of the arrays-these will keep track of the current index of the current element to populate/visit in each. countFirst will keep track of the current index in first to visit, countSecond the current index in second to visit, and countMerge the current index in merge to populate Within this while-loop, you will need to add the code to populate merge (either with firs?'s element or second's element). Increment either countFirst or countSecond depending on which array you used. In either case, also increment countMerge Note that as long as countFirst is less than first's length and countSecond is less than second's length you need to keep traversing within the while-loop a. b. c. 3. Once one of the two arrays is completely traversed, you must still finish traversing the array that was only partially traversed. The code has been given to identify which one was partially traversed. You must add code that finishes traversing this array, assigning values to the merge array Traverse and output the merge array 4. ud ni
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started