
Patrick B. answered 07/11/20
Math and computer tutor/teacher
public class RecursiveSelectionSorting
{
public static void Sort(int[ ] data)
{
sort(data, 0);
}
private static void sort(int[ ] data, int beginIndex)
{
if(beginIndex==data.length-1) return;
int minIndex = beginIndex;
for(int i=beginIndex; i<data.length; i++) {
if(data[i]<data[minIndex]) minIndex = i;
}
swap(data, beginIndex , minIndex);
sort(data,beginIndex+1);
}
private static void swap(int[ ] data, int p, int q)
{
int temp = data[p];
data[p] = data[q];
data[q] = temp;
}
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]);
}
}
}
Sara P.
Thank you so much!07/12/20