Question: You wrote an insertInOrder method to insert a new value into an array of ints, at the proper index, thus keeping the arary in sorted
You wrote an insertInOrder method to insert a new value into an array of ints, at the proper index, thus keeping the arary in sorted order. You also wrote a bSeach that gets called at the top. The code produces the correct insertion of the new value and the final condition of the array is perfect and correct -BUT- it does something redundant and wasteful that demonstrates the programmer did not understand why the bSearch was claled in the first place.

#3) WORTH 4% You wrote an insertInOrder method to insert a new value into an array of ints, at the proper index, thus keeping the array in sorted order. You also wrote a bSearch that gets called at the top. The code produces the correct insertion of the new value and the final condition of the array is perfect and correct -BUT..it does something redundant and wasteful that demonstrates the programmer did not understand why the bSearch was called in the first place. ) static void insertInOrder ( int[] arr, int count, int newVal { int index = bSearch( arr, count, newval ); if(index=index && arr[i]>newval ; i--) arr[i+1]=arr[i]; arr[index] = newVal; } A B the for loop compares the incoming newVal to the array elements. This is not necessary the for loop copies elements at [i] up to [i+1]. This is not necessary the last line of code copies the new Val into the array. This is not necessary the index brought back from bSearch is inverted. This is not necessary| D
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
