Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: Integer Arrays sorting SAMPLE OUTPUTS: *Array* before selection sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] --Found next smallest value: 2

JAVA: Integer Arrays sorting

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

SAMPLE OUTPUTS:

*Array* before selection sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] --Found next smallest value: 2 at index 1. ---Swap elements at index 0 and 1 -Array after loop where i= 0: [2, 11, 34, 14, 95, 26, 7, 18, 9, 16] --Found next smallest value: 7 at index 6. ---Swap elements at index 1 and 6 -Array after loop where i= 1: [2, 7, 34, 14, 95, 26, 11, 18, 9, 16] --Found next smallest value: 9 at index 8. ---Swap elements at index 2 and 8 -Array after loop where i= 2: [2, 7, 9, 14, 95, 26, 11, 18, 34, 16] --Found next smallest value: 11 at index 6. ---Swap elements at index 3 and 6 -Array after loop where i= 3: [2, 7, 9, 11, 95, 26, 14, 18, 34, 16] --Found next smallest value: 14 at index 6. ---Swap elements at index 4 and 6 -Array after loop where i= 4: [2, 7, 9, 11, 14, 26, 95, 18, 34, 16] --Found next smallest value: 16 at index 9. ---Swap elements at index 5 and 9 -Array after loop where i= 5: [2, 7, 9, 11, 14, 16, 95, 18, 34, 26] --Found next smallest value: 18 at index 7. ---Swap elements at index 6 and 7 -Array after loop where i= 6: [2, 7, 9, 11, 14, 16, 18, 95, 34, 26] --Found next smallest value: 26 at index 9. ---Swap elements at index 7 and 9 -Array after loop where i= 7: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] --Found next smallest value: 34 at index 8. ---Swap elements at index 8 and 8 -Array after loop where i= 8: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] *Array* after selection sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press key to continue

*Array* before insertion sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] --Insert 2 into sorted numbers before 2 ---Swap elements at index 1 and 0 -Array after loop where i= 1: [2, 11, 34, 14, 95, 26, 7, 18, 9, 16] --Insert 34 into sorted numbers before 34 -Array after loop where i= 2: [2, 11, 34, 14, 95, 26, 7, 18, 9, 16] --Insert 14 into sorted numbers before 14 ---Swap elements at index 3 and 2 -Array after loop where i= 3: [2, 11, 14, 34, 95, 26, 7, 18, 9, 16] --Insert 95 into sorted numbers before 95 -Array after loop where i= 4: [2, 11, 14, 34, 95, 26, 7, 18, 9, 16] --Insert 26 into sorted numbers before 26 ---Swap elements at index 5 and 4 ---Swap elements at index 4 and 3 -Array after loop where i= 5: [2, 11, 14, 26, 34, 95, 7, 18, 9, 16] --Insert 7 into sorted numbers before 7 ---Swap elements at index 6 and 5 ---Swap elements at index 5 and 4 ---Swap elements at index 4 and 3 ---Swap elements at index 3 and 2 ---Swap elements at index 2 and 1 -Array after loop where i= 6: [2, 7, 11, 14, 26, 34, 95, 18, 9, 16] --Insert 18 into sorted numbers before 18 ---Swap elements at index 7 and 6 ---Swap elements at index 6 and 5 ---Swap elements at index 5 and 4 -Array after loop where i= 7: [2, 7, 11, 14, 18, 26, 34, 95, 9, 16] --Insert 9 into sorted numbers before 9 ---Swap elements at index 8 and 7 ---Swap elements at index 7 and 6 ---Swap elements at index 6 and 5 ---Swap elements at index 5 and 4 ---Swap elements at index 4 and 3 ---Swap elements at index 3 and 2 -Array after loop where i= 8: [2, 7, 9, 11, 14, 18, 26, 34, 95, 16] --Insert 16 into sorted numbers before 16 ---Swap elements at index 9 and 8 ---Swap elements at index 8 and 7 ---Swap elements at index 7 and 6 ---Swap elements at index 6 and 5 -Array after loop where i= 9: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]

*Array* after insertion sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press key to continue

*Array* before bubble sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] -Starting at index 1, bubbling up highest numbers until index 9 ---Swap elements at index 0 and 1 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 ---Swap elements at index 8 and 9 --Array after loop with i= 1: [2, 11, 14, 34, 26, 7, 18, 9, 16, 95]. -Starting at index 2, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 --Array after loop with i= 2: [2, 11, 14, 26, 7, 18, 9, 16, 34, 95]. -Starting at index 3, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 --Array after loop with i= 3: [2, 11, 14, 7, 18, 9, 16, 26, 34, 95]. -Starting at index 4, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 --Array after loop with i= 4: [2, 11, 7, 14, 9, 16, 18, 26, 34, 95]. -Starting at index 5, bubbling up highest numbers until index 9 ---Swap elements at index 1 and 2 ---Swap elements at index 3 and 4 --Array after loop with i= 5: [2, 7, 11, 9, 14, 16, 18, 26, 34, 95]. -Starting at index 6, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 --Array after loop with i= 6: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 7, bubbling up highest numbers until index 9 --Array after loop with i= 7: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 8, bubbling up highest numbers until index 9 --Array after loop with i= 8: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 9, bubbling up highest numbers until index 9 --Array after loop with i= 9: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95].

*Array* after bubble sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press key to continue

*Array* before improved bubble sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] -Starting at index 1, bubbling up highest numbers until index 9 ---Swap elements at index 0 and 1 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 ---Swap elements at index 8 and 9 --Array after loop with k= 1: [2, 11, 14, 34, 26, 7, 18, 9, 16, 95]. -Starting at index 2, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 --Array after loop with k= 2: [2, 11, 14, 26, 7, 18, 9, 16, 34, 95]. -Starting at index 3, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 --Array after loop with k= 3: [2, 11, 14, 7, 18, 9, 16, 26, 34, 95]. -Starting at index 4, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 --Array after loop with k= 4: [2, 11, 7, 14, 9, 16, 18, 26, 34, 95]. -Starting at index 5, bubbling up highest numbers until index 9 ---Swap elements at index 1 and 2 ---Swap elements at index 3 and 4 --Array after loop with k= 5: [2, 7, 11, 9, 14, 16, 18, 26, 34, 95]. -Starting at index 6, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 --Array after loop with k= 6: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 7, bubbling up highest numbers until index 9 --Array after loop with k= 7: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. Improved bubble sort executed 2 less loops.

*Array* after improved bubble sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press key to continue

(pg1) Description This program will use an array of integers and provide multiple ways to sort the contents. To better understand the mechanics, your sort methods wi include some additional print statements to show the "decisions" being made in each algorithm. See the sample output. Requirements . Method main) o Use the following main) method in your program to execute your methods See the output at the end for an example of what your methods will display: public static void main(String] args) Scanner input new Scanner(System.in); // test selection sort int] numbersl(11,2,34, 14,95,26,7,18,9,16); System.out.printf(" *Array" before selection sort: %s ",Arrays.tostring(numbers1)); selectionSort (numbers1); System.out.printf(" *Array" after selection sort: %s ", Arrays . toString(numbers1)); System.out.println("Press

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago