For this daily, write a function named insert_into_sorted that will insert a value into an array of ASCENDING order sorted values. A CPP file (insert_sorted.cpp) has been provided. It contains the prototype statement for the insert_into_sorted function, a function named print_arrays, and a complete int main(). The print_arrays function displays the value that was inserted into the sorted array and the values in two arrays of integers. Add the insert_into_sorted function that is described below to the file. DO NOT change the code that is provided in int main() or the print_arrays function. int insert_into_sorted(int source[], int source_len, int destination[], int new_elem) The insert_into_sorted function fills a new array by copying values from an array of ASCENDING order sorted values and inserting a value into the correct position so the values in the new array remain sorted in ASCENDING order. The function takes four arguments: 1. an array of integers that holds the sorted values (source in the header) 2. an integer that represents the number of values that the source array contains (source_len) 3. an array of integers that the values should be copied into (destination) 4. an integer that represents the number to be inserted (new_elem) The function returns an integer: 0 if the number of values that the source array contains is less than 1, otherwise it returns 1. It is okay to assume that the array that is being filled (destination) has been properly declared to have room for the values from the source array and the inserted value. File You Must Submit Place the completed program code in a source file named insert_sorted.cpp. This daily requires that only the insert_into_sorted function is completed and added to the code that has been provided. Examples of how the insert_into_sorted function works Example 1 Assume that the following has been passed to the function source_len source 2 4 6 8 10 12 6 [0] [1] [2] [3] [4] [5] new_elem destination 5 [0] [1] [2] [3] [4] [5] [6] The goal is to insert the value 5 (new_elem) into the correct sorted position in destination. To start, the values in source that are smaller than 5 should be copied into the destination array. destination 2 4 [0] [1] [2] [3] [4] [5] [6] Next, the 5 should be copied into the destination array. destination 2 4 5 [0] [1] [2] [3] [4] [5] [6] Finally, any remaining values in the source array should be copied into the destination array. destination 2 4 5 6 8 10 12 [0] [1] [2] [3] [4] [5] [6]

The output that is produced by the program will vary based on the values that are entered when the program is executed. The output that is shown below is what the program will produce when it is run in an environment such as Dev C++ or XCode. When it is run through the Auto Grader, the portions that ask for values WILL NOT show the values that are entered. The value in this run is used for diff 1 Test Number? 1 The inserted value 15 The original array contains {10, 20} The new array contains {10, 15, 20} The value in this run is used for diff 2 Test Number? 2 The inserted value 5 The original array contains {10, 20, 30} The new array contains {5, 10, 20, 30}

Q&A Education