I'm trying to do selection sort for objects...But it wont work, please help. We were told to change the first one to do objects. Any help appreciated
public static void selectionSort (int[] numbers)
{
int min, temp;
for (int index = 0; index < numbers.length-1; index++)
{
min = index;
for (int scan = index+1; scan < numbers.length; scan++)
if (numbers[scan] < numbers[min])
min = scan;
// Swap the values
temp = numbers[min];
numbers[min] = numbers[index];
numbers[index] = temp;
}
}
public static void selectionSort (Comparable[] objects)
{
int min;
Comparable temp;
for (int index = 0; index < objects.length-1; index++)
{
min = index;
for (int scan = index+1; scan < objects.length; scan++)
if (objects[min].compareTo(objects[scan]))
min = scan;
// Swap the values
temp = objects[min];
objects[min] = objects[index];
objects[index] = temp;
}
}