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...
icon
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
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
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
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY