Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My library > COSC 2 2 0 : Data Structures and Algorithms home > 3 . 1 0 : LAB: Insertion sort zyBooks catalog 3

My library > COSC 220: Data Structures and Algorithms home >3.10: LAB: Insertion sort
zyBooks catalog
3.10 LAB: Insertion sort
The program has four steps:
Read the size of an integer array, followed by the elements of the array (no duplicates).
Output the array.
Perform an insertion sort on the array.
Output the number of comparisons and swaps performed.
main0 performs steps 1 and 2.
Implement step 3 based on the insertion sort algorithm in the book. Modify insertionSort 0 to:
Count the number of comparisons performed.
Count the number of swaps performed.
Output the array during each iteration of the outside loop.
Complete main() to perform step 4, according to the format shown in the example below.
Hints: In order to count comparisons and swaps, modify the while loop in insertionSort(0. Use static variables for comparisons and swaps.
The program provides three helper methods:Ex: When the input is:ks My library > COSC 220: Data Structures and Algorithms home >3.10: LAB: Insertion sort
zyBooks catalog
void swap(int[] nums, int j, int k)
Ex: When the input is:
6,3,2,1,5,9,8
the output is:
\table[[3,2,1,5,9,8],[2,3,1,5,9,8],[1,2,3,5,9,8],[1,2,3,5,9,8],[1,2,3,5,9,8],[1,2,3,5,8,9]]
573528.4271126.qx3zqy7
LAB
ACTIVITY
3.10.1: LAB: Insertion sort
010
LabProgram.java
Load default template...
\table[[66],[67],[68],[69],[70],[71],[72],[73],[74],[75]]
// Step 2: Output the numbers array printNums(numbers);
System.out.println();
// Step 3: Sort the numbers array using insertion sort insertionSort(numbers);
System.out.println();
// Step 4: Output the number of comparisons and swaps performedzyBooks My library > COSC 220: Data Structures and Algorithms home >3.10 : LAB: Insertion sort
zyBooks catalog
The program has four steps:
Read the size of an integer array, followed by the elements of the array (no duplicates).
Output the array.
Perform an insertion sort on the array.
Output the number of comparisons and swaps performed.
main( performs steps 1 and 2.
Implement step 3 based on the insertion sort algorithm in the book. Modify insertionSort0 to:
Count the number of comparisons performed.
Count the number of swaps performed.
Output the array during each iteration of the outside loop.
Complete main() to perform step 4, according to the format shown in the example below.
Hints: In order to count comparisons and swaps, modify the while loop in insertionSort0. Use static variables for comparisons and swaps The program provides three helper
methods:Ex:When the input is:
6321598
the output is:
321598
231598
123598
123598
123598
123589
comparisons: 7
swaps: 4
image text in transcribed

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

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions