Computers and Technology, 09.01.2021 18:20 21vdawson
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
Answers: 1
Computers and Technology, 22.06.2019 07:30
By refraining from constructing a building until they are certain that it will not cause harm to the environment, an organization is adhering to the
Answers: 2
Computers and Technology, 22.06.2019 18:30
Which cultural aspect does this type of song best portray? a german polka dance
Answers: 1
Computers and Technology, 23.06.2019 21:30
Which of the following includes the three primary network access technologies? dsl, cable modem, broadband lan, wan, man voip, uc, iptv tcp/ip, ftp, dhcp
Answers: 2
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
The following sort method correctly sorts the integers in elements into ascending order.
Line 1: pu...
Biology, 20.03.2021 23:30
History, 20.03.2021 23:30
Arts, 20.03.2021 23:30
Mathematics, 20.03.2021 23:30
Mathematics, 20.03.2021 23:30
Chemistry, 20.03.2021 23:30
History, 20.03.2021 23:30
Mathematics, 20.03.2021 23:30
Biology, 20.03.2021 23:30
English, 20.03.2021 23:30
History, 20.03.2021 23:30