Sarah P.

asked • 07/25/20

Method shown below can do “Insertion Sorting” for integer arrays. Modify it so that it can sort any type array, object types and primitive types.

public static void sort(int[] data) {

int i, j, temp;

for(i=1; i<data.length; i++) {

temp = data[i];

for(j=i-1; j>=0; j--) {

if(data[j]>temp) data[j+1] = data[j];

else break;

}

data[j+1] = temp;

}

}

1 Expert Answer

By:

Gaurav P. answered • 07/25/20

Tutor
New to Wyzant

Computer Science Student with Teaching Experience

Sarah P.

Thank you so much!
Report

07/26/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.