public class SortDemo
{
public static void main (String[] args)
{
Fraction[] f = new Fraction [3] ;
f[O] new Fraction(3,4);
f[1] new Fraction(1,2);
f[2] new Fraction(2,3);
Integer[] n = new Integer[3];
n[O] new Integer(7);
n[1] = new Integer(5);
n[2] = new Integer(2);
String [] s = {"Jonathan","Callum","Melissa"};
System.out.println("Original Values\n");
for (int i = 0; i < f.length; i++)
System.out.println (f [L] + II II + n [i].intValue 0
+ II II + s [i]) ;
selectSort(f);
selectSort(n);
selectSort(s);
System.out.println("\nSorted Values\n");
for (int i = 0; i < f.length; i++)
System.out.println (f [i] + II II + n [i].intValue 0
+ II II + s [i]) ;
}
public static void selectSort (Comparable[] list)
{
for (int-top = list.length - 1; top> 0; top--)
{
int largeLoc = 0;
for (int i = 1; i <= top; i++)
if (list[largeLoc] .compareTo(list[i]) < 0)
largeLoc = i;
Comparable temp = list [top];
list[top] = list [largeLoc] ;
list[largeLoc] = temp;
}
}
}
|