So I made this selection sort code, but I want it to increment one loop of the sort each time the function is called.
So I thought okay. Why not just remove the outer for loop and replace index with a static variable up top and increment it each time the function finishes its operations. But that just messed up the sort really badly. Can someone help?
Question: How do I go through the sort one step at a time each time the function is called?
I don't want it to sort the entire thing all at once
private static void selectionSort(int[] array) {
for (int index = 0; index < array.length; index++) {
int currentMin = array[index];
int indexOfMin = index;
for(int j = index+1; j < array.length; j++) {
if(array[j] < currentMin) {
currentMin = array[j];
indexOfMin = j;
}
}
swap(array, index, indexOfMin);
}
}
private static void swap(int[] a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
312->132->123?