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, 22.06.2019 05:30
Agood flowchart alludes to both the inputs and outputs you will need to receive and give to the user. true or false?
Answers: 3
question
Computers and Technology, 22.06.2019 22:30
Who needs to approve a change before it is initiated? (select two.) -change board -client or end user -ceo -personnel manager -project manager
Answers: 1
question
Computers and Technology, 23.06.2019 05:00
In cell b18, enter a formula to calculate the amount budgeted for meals. this amount is based on the daily meal allowance and the total travel days (# of nights+1).
Answers: 1
question
Computers and Technology, 23.06.2019 21:50
Description: write function lastfirst() that takes one argument—a list of strings of the format "lastname, firstname" —and returns a list consisting of two lists: (a) a list of all the last names (b) a list of all the first names
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
Mathematics, 22.02.2021 08:50
question
Chemistry, 22.02.2021 08:50
question
Mathematics, 22.02.2021 08:50
question
Mathematics, 22.02.2021 08:50
question
Health, 22.02.2021 08:50
question
Mathematics, 22.02.2021 08:50
question
Mathematics, 22.02.2021 08:50
question
Mathematics, 22.02.2021 08:50
Questions on the website: 13722359