subject

The following sort method correctly sorts the integers in elements into ascending order. Line 1: public static void sort(int[] elements)
Line 2: {
Line 3: for (int j = 1; j < elements. length; j++)
Line 4: {
Line 5: int temp = elements[j];
Line 6: int possibleIndex = j;
Line 7: while (possibleIndex > 0 && temp < elements[possibleIndex - 1])
Line 8: {
Line 9: elements[possibleIndex] = elements[possibleIndex - 1];
Line 10: possibleIndex--;
Line 11: }
Line 12: elements[possibleIndex] = temp;
Line 13: }
Line 14: }
Consider the following three proposed changes to the code:
Change 1
Replace line 3 with:
Line 3: for (int j = elements. length - 2; j >= 0; j--)
Change 2
Replace line 7 with:
Line 7: while (possibleIndex > 0 && temp > elements[possibleIndex - 1])
Change 3
Replace line 7 with:
Line 7: while (possibleIndex < elements. length - 1 && temp < elements[possibleIndex + 1])
and replace lines 9-10 with:
Line 9: elements[possibleIndex] = elements[possibleIndex + 1];
Line 10: possibleIndex++;
Suppose that you wish to change the code so that it correctly sorts the integers in elements into descending order rather than ascending order. Which of the following best describes which combinations of the proposed changes would achieve this goal?
A) Enacting any of the three changes individually
B) Enacting changes 1 and 2 together, or enacting change 3 by itself
C) Enacting changes 1 and 3 together, or enacting change 2 by itself
D) ONLY enacting changes 1 and 2 together
E) ONLY enacting change 2 by itself

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
List the five on-board vehicle subsystems
Answers: 1
question
Computers and Technology, 23.06.2019 15:20
What does a bonus object do? a. subtracts lives b. keeps track of a player's health c. gives a player an advantage d. makes text appear
Answers: 1
question
Computers and Technology, 24.06.2019 00:50
Which player type acts on other players? a. killer b. achiever c. explorer d. socializer
Answers: 1
question
Computers and Technology, 24.06.2019 02:40
Has anyone seen my grandma shes been gone for 4 years already
Answers: 1
You know the right answer?
The following sort method correctly sorts the integers in elements into ascending order. Line 1: pu...
Questions
question
Mathematics, 17.12.2020 18:50
question
Mathematics, 17.12.2020 18:50
question
Social Studies, 17.12.2020 18:50
question
Mathematics, 17.12.2020 18:50
question
Social Studies, 17.12.2020 18:50
question
Mathematics, 17.12.2020 18:50
question
Mathematics, 17.12.2020 18:50
Questions on the website: 13722362