
Patrick B. answered 07/11/20
Math and computer tutor/teacher
public class RecursiveInsertionSorting
{
public static void Sort(int[ ] data)
{
sort(data,1);
}
private static void sort(int[] data, int endIndex)
{
if (endIndex==data.length) { return; }
int i;
int temp = data[endIndex];
/* Move elements of arr[0..i-1], that are
greater than key, to one position ahead
of their current position */
for (i=endIndex-1; i >= 0; i--)
{
if (data[i]>temp)
data[i + 1] = data[i];
else break;
}
data[i+ 1] = temp;
sort(data,endIndex+1);
}
public static void main (String args[])
{
int data[] = { 24,12,18,16,2,13,11,19,15,17,10,7,21,5,20,6,3,9,4,22,8,23};
RecursiveInsertionSorting x = new RecursiveInsertionSorting();
x.Sort(data);
for (int iLoop=0; iLoop<data.length; iLoop++)
{
System.out.println(data[iLoop]);
}
}
}

Patrick B.
Denada. By the way, there is compile error in the problem you posted... extra break statement that is orphaned. I deleted it.07/12/20
Sara P.
Thank you so much!07/12/20