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?

Enacting changes 1 and 2 together, or enacting change 3 by itself

ONLY enacting change 2 by itself

Enacting any of the three changes individually

ONLY enacting changes 1 and 2 together

Enacting changes 1 and 3 together, or enacting change 2 by itself

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
What must you do before formatting a paragraph?
Answers: 1
question
Computers and Technology, 22.06.2019 09:00
What is one way in which tablets differ from laptops and notebooks? tablets are designed for touch-based interaction. tablets are designed to be used as desktops. tablets are designed for input via a keyboard and mouse. tablets are designed to be larger than laptops.
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
What is a scenario where records stored in a computer frequently need to be checked
Answers: 2
question
Computers and Technology, 23.06.2019 22:20
If i uninstall nba 2k 19 from my ps4 will my career be gone forever?
Answers: 2
You know the right answer?
The following sort method correctly sorts the integers in elements into ascending order. Line 1: pu...
Questions
question
History, 18.02.2021 14:00
question
Mathematics, 18.02.2021 14:00
question
Arts, 18.02.2021 14:00
question
Physics, 18.02.2021 14:00
question
Mathematics, 18.02.2021 14:00
question
Mathematics, 18.02.2021 14:00