Below is some java code that is supposed to sort an array of shapes based on their area(compareto method takes care of that). However, it never sorts the array correctly and i don't know why. here is the code: public static Shape[] sort(Shape[] array) { int indexOfMin =0; for(int j=0; j<array.length; j++) { for(int i =indexOfMin; i<array.length; i++) { if(array.compareTo(array[indexOfMin]) == -1) { indexOfMin=i; } } swap(indexOfMin, j, array); indexOfMin=j+1; } return array; } The idea is that it goes through the list, starting at j, and finds the minimum value then swaps it with j. then j iterates and it does it again. What is wrong with this code can anyone help?
Okay so disregard the title. I fixed the sort. the sort you see above works fine (before i had the inner loop start at i=0) I do have another question though. what kind of sort is this? is it an insertion sort?