Question: JAVA please// I have already done code but I need help to fix the errors I am getting. please repond will a full code to






17.12 LAB: Insertion sort The program has four steps: 1. Read the size of an integer array, followed by the elernents of the array (no duplicates) 2. Output the array. 3. Perform an insertion sort on the array. 4. Output the number of comparisons and swaps performed. main0 nerforms steps 1 and 2 Implement step 3 based on the insertion sort algorithm in the book. Modify insertionsorte to - Count the number of comparisons performed - Count the number of swaps performed. - Output the array duning each iteration of the outside loop. Complete maing to perform step 4 a according to the format shown in the example below. Hints: in order to count comporisons and swaps, modily the while loop in insertionsort0. Use static variables for camparisons and awss The program provides three helper methodn: 1f Hhend and rekum an ortay of intedeta. 11 Thin tirat intibget read in number of integeca that toliok. ine 11 repaklurin 0 1/ Read and rotuzn an array of integers. I/ The first integer read is number of integers that follow. int [1 readiums ( ) 1/ print the numbers in the array, separated by spaces /1. (No space or newline before the IIrst number or after the last. void printkioms (int {1 nums) If Exchange nums {j} and nums {k]. void swap (int (1 nums, int j, int k). Ex. When the input is: 6321=598 - the output is: 3211212322221133335555559599986988898 ecimparioons 7 annegi 4 Load default template... import java. util. Scanner; public class LabProgram \{ public static int readNums ) \{ Scanner sc= new Scanner(System, in); int n; nusc.nextInt(); int nums ]= new int [n]; for (int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
