Question: Insertion Sort- I just need you to comment on each line of the algorithms only. Remember I just want the comment on algorithms line only,

Insertion Sort- I just need you to comment on each line of the algorithms only. Remember I just want the comment on algorithms line only, what is that line of code do and used for. This code was in java language.

public class IntegerList { int[] list; //values in the list

//------------------------------------------------------- //create a list of the given size //------------------------------------------------------- public IntegerList(int size) { list = new int[size]; }

//------------------------------------------------------- //fill array with integers between 1 and 100, inclusive //------------------------------------------------------- public void randomize() { for (int i=0; i

//------------------------------------------------------- //print array elements with indices //------------------------------------------------------- public void print() { for (int i=0; i

//------------------------------------------------------- //insertion sorts array elements //-------------------------------------------------------

public void insertionSort() { for (int i = 1; i < list.length; i++) { int key = list[i]; int position = i; while(position > 0 && list[position -1] > key) { list[position] = list[position -1]; position--; } list [position] = key; } } }

public class Tester { public static void main(String args[]) { IntegerList list = new IntegerList(5); list.randomize(); list.print(); System.out.println(); list.insertionSort(); list.print(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!