42. Consider the two methods below? public static void sort (ArrayList list) { for (int p = 0; p < list.size(); p++) { } int smallest = p; for (int q = p+1; q list, int x, int y) { int temp = list.get(x); list.set(x,list.get(y)); list.set(y,temp); 42. Which of the following sorts is implemented above? Bubble Sort Selection Sort Insertion Sort Merge Sort None of the above

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

all questions are in the pics, thanks!

42. Consider the two methods below?
public static void sort (ArrayList<Integer> list)
{
for (int p = 0; p < list.size(); p++)
{
int smallest = p;
for (int q = p+1; q < list.size(); q++)
{
if (list.get(q) < list.get(smallest))
{
smallest = q;
}
}
swap(list,p,smallest);
}
}
private static void swap (ArrayList<Integer> list, int x, int y)
{
int temp = list.get(x);
list.set(x,list.get(y));
list.set(y,temp);
42. Which of the following sorts is implemented above?
Bubble Sort
Selection Sort
Insertion Sort
Merge Sort
None of the above
Transcribed Image Text:42. Consider the two methods below? public static void sort (ArrayList<Integer> list) { for (int p = 0; p < list.size(); p++) { int smallest = p; for (int q = p+1; q < list.size(); q++) { if (list.get(q) < list.get(smallest)) { smallest = q; } } swap(list,p,smallest); } } private static void swap (ArrayList<Integer> list, int x, int y) { int temp = list.get(x); list.set(x,list.get(y)); list.set(y,temp); 42. Which of the following sorts is implemented above? Bubble Sort Selection Sort Insertion Sort Merge Sort None of the above
43. Consider the code segment and sort method below.
ArrayList<Integer> list = new ArrayList<Integer>();
for (int k = 1; k <= 20; k++)
{
}
sort(list);
for (int item: list)
int rnd = (int) (Math.random() * 90 + 10);
list.add(rnd);
}
System.out.println();
public static void sort (ArrayList<Integer> list)
{
System.out.print(item + " ");
}
for (int p = 0; p < list.size(); p++)
{
}
int smallest = p;
for (int q = p+1; q < list.size(); q++)
if (list.get(q) < list.get(smallest))
smallest = q;
swap(list,p,smallest);
private static void swap (ArrayList<Integer> list, int x, int y)
{
int temp = list.get(x);
list.set(x,list.get(y));
list.set(y,temp);
43. What can be printed when the program is executed?
11 18 22 22 31 33 41 41 48 57 60 65 72 75 78 81 90 90 92 97
89 89 88 86 86 81 79 69 64 63 57 55 51 51 45 37 33 18 17 15
O 7 11 26 28 29 31 41 43 44 47 50 51 63 64 67 74 89 91 93 97
93 83 70 67 59 57 52 51 40 34 30 27 21 18 18 16 14 11 10 10
Both (B) and (D)
Transcribed Image Text:43. Consider the code segment and sort method below. ArrayList<Integer> list = new ArrayList<Integer>(); for (int k = 1; k <= 20; k++) { } sort(list); for (int item: list) int rnd = (int) (Math.random() * 90 + 10); list.add(rnd); } System.out.println(); public static void sort (ArrayList<Integer> list) { System.out.print(item + " "); } for (int p = 0; p < list.size(); p++) { } int smallest = p; for (int q = p+1; q < list.size(); q++) if (list.get(q) < list.get(smallest)) smallest = q; swap(list,p,smallest); private static void swap (ArrayList<Integer> list, int x, int y) { int temp = list.get(x); list.set(x,list.get(y)); list.set(y,temp); 43. What can be printed when the program is executed? 11 18 22 22 31 33 41 41 48 57 60 65 72 75 78 81 90 90 92 97 89 89 88 86 86 81 79 69 64 63 57 55 51 51 45 37 33 18 17 15 O 7 11 26 28 29 31 41 43 44 47 50 51 63 64 67 74 89 91 93 97 93 83 70 67 59 57 52 51 40 34 30 27 21 18 18 16 14 11 10 10 Both (B) and (D)
Expert Solution
Step 1

42) We have to choose the correct sort method which is implemented in the given code from the options.

43) We have to choose the correct answer from the given options that can be printed when the program is executed.

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT