Make the code below give out an output the turns the arraylist from highest number to lowest number for both arraylists
Make the code below give out an output the turns the arraylist from highest number to lowest number for both arraylists
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Make the code below give out an output the turns the arraylist from highest number to lowest number for both arraylists
use java
![// note: we start with 1 instead of 0
for (int i = 1; i < arr.length; i++)
{
int curNumber = arr[i];
35
36
37-
38
39
// Set index to be place to the left
int curIndex = i-1;
40
41
42
// We are still inbounds and the current number
// is less than the current index
while ( curIndex >= 0 && arr[curIndex] > curNumber)
{
// Shift the value at curIndex to the right one place
arr[curIndex+1] = arr[curIndex];
curIndex--;
}
43
44
45
46 -
47
48
49
50
51
// Put this number in the proper location
arr[curIndex + 1] = curNumber;
52
53
54
55
}
56
57](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5ce8c54e-2b59-4ae4-af38-4aa6183ed8ad%2Fdfe79265-22b9-4933-a767-8a6bbe0de773%2Fy2cncnm_processed.png&w=3840&q=75)
Transcribed Image Text:// note: we start with 1 instead of 0
for (int i = 1; i < arr.length; i++)
{
int curNumber = arr[i];
35
36
37-
38
39
// Set index to be place to the left
int curIndex = i-1;
40
41
42
// We are still inbounds and the current number
// is less than the current index
while ( curIndex >= 0 && arr[curIndex] > curNumber)
{
// Shift the value at curIndex to the right one place
arr[curIndex+1] = arr[curIndex];
curIndex--;
}
43
44
45
46 -
47
48
49
50
51
// Put this number in the proper location
arr[curIndex + 1] = curNumber;
52
53
54
55
}
56
57
![1 import java.util.Arrays;
2
3 public class InsertionSort extends ConsoleProgram
4- {
public void run()
{
int[] array1
int[] array2
5
{9, 8, 7, 6, 5, 4, 3, 2, 1};
{5, 6, 4, 8, 9, 7, 3, 1, 2};
7
8
System.out.print("First array: ");
System.out.println(Arrays.tostring(array1));
System.out.print("Second array: ");
System.out.println(Arrays.tostring(array2));
System.out.println();
10
11
12
13
14
15
16
17
18
19
20
// sort first array
insertionSort(array1);
// sort second array
insertionSort(array2);
System.out.print("First array sorted: ");
System.out.println(Arrays.tostring(array1));
System.out.print("Second array sorted: ");
System.out.println(Arrays.tostring(array2));
}
21
22
23
24
25
26
/*
* Insertion sort takes in an array of integers and
returns a sorted array of the same integers.
*/
public static void insertionSort(int[] arr)
{
System.out.println(Arrays.tostring(arr));
27-
28
*
29
30
31
32-
33
34](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5ce8c54e-2b59-4ae4-af38-4aa6183ed8ad%2Fdfe79265-22b9-4933-a767-8a6bbe0de773%2Fhpvkt9e_processed.png&w=3840&q=75)
Transcribed Image Text:1 import java.util.Arrays;
2
3 public class InsertionSort extends ConsoleProgram
4- {
public void run()
{
int[] array1
int[] array2
5
{9, 8, 7, 6, 5, 4, 3, 2, 1};
{5, 6, 4, 8, 9, 7, 3, 1, 2};
7
8
System.out.print("First array: ");
System.out.println(Arrays.tostring(array1));
System.out.print("Second array: ");
System.out.println(Arrays.tostring(array2));
System.out.println();
10
11
12
13
14
15
16
17
18
19
20
// sort first array
insertionSort(array1);
// sort second array
insertionSort(array2);
System.out.print("First array sorted: ");
System.out.println(Arrays.tostring(array1));
System.out.print("Second array sorted: ");
System.out.println(Arrays.tostring(array2));
}
21
22
23
24
25
26
/*
* Insertion sort takes in an array of integers and
returns a sorted array of the same integers.
*/
public static void insertionSort(int[] arr)
{
System.out.println(Arrays.tostring(arr));
27-
28
*
29
30
31
32-
33
34
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY