-
Top Down Insertion Sort
Hello, I am probably being stupid but I am trying to learn how to do top down computation and I am trying to do a top down recursive insertion sort algorithm. I am getting really confused, at one point i thought I was getting there but now I just keep causeing stack overflows, can anyone offer some help and advice?
m = number of elements that are currently not sorted
Code:
public static int[] sort(int m, int [] sortarray){
if(m>2){
int current = m-1;
int last = current - 1;
for(int i = 0; i<current; m++){
if(sortarray[current]<sort(m-1, sortarray)[last]){
int temp;
temp = sortarray[last];
sortarray[last] = sortarray[current];
sortarray[current] = temp;
temp = 0;
current--;
last--;
}
}
}
return sortarray;
}