Question: Question 22 Consider the following implementation of Insertion Sort Change the code above so that it sorts from greatest to least instead of least to
Question 22
Consider the following implementation of Insertion Sort
Change the code above so that it sorts from greatest to least instead of least to greatest.
Question 23
Write a program that creates a Linear search which return the sum of the two elements surrounding the key value, and return 0 if not found.
Eg. if array = [0, 2, 4, 6] and key = 4 then the function returns 8.
if array = [0, 2, 4, 6] and key = 6 then the function returns 4.
if array = [0, 2, 4, 6] and key = 5 then the function returns 0.
public static int weirdLinearSearch(int[] arr){
for (int i = 0; i
if (_______________________________){ toReturn += array[i - 1]; }
if (_______________________________){
toReturn += array[i+1];
} _______________________________;
}
_____________________________________
}
Please fill in the blanks by writing each blank a new line.
Question 24
Create the following function:
"Given base and n that are both 1 or more, compute recursively (no loops) the value of base to the n power, so powerN(3, 2) is 9 (3 squared).
powerN(3, 1) ? 3 powerN(3, 2) ? 9 powerN(3, 3) ? 27"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
