public class Sort { public static void selectionSort(GeometricObject[] list) { for (int i = 0; i < list.length - 1; i++) { /* ----------------------------------------------- Find the minimum in the list[i..list.length-1] ----------------------------------------------- */ GeometricObject min = list[i]; // Assume first element is min int minIndex = i; // Index where min is found for ( int k = minIndex+1; k < list.length; k++ ) if ( list[k].getArea() < min.getArea() ) // Found smaller element { min = list[k]; // Update min value minIndex = k; // Update index } /* ------------------------------------------------------ Swap list[i] with list[minIndex] if necessary; ------------------------------------------------------ */ if ( minIndex != i ) { // Swap list[minIndex] and list[i] GeometricObject help = list[minIndex]; list[minIndex] = list[i]; list[i] = help; } } } }