Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions