package mysorting;
public class Sorting
{
public static void BubbleSort(Person a[])
{
for (int i = 0; i < a.length - 1; i++)
{
for (int j = 0; j < a.length - i - 1; j++)
{
if (a[j].compareTo(a[j+1]) > 0)
{
Person temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
} // end if
} // end for j
} // end for i
} // end method Bubblesort
public static void main(String args[])
{
Person a[] = new Person[4];
a[0] = new Person("mary");
a[1] = new Person("jeremy");
a[2] = new Person("susan");
a[3] = new Person("josh");
Sorting.BubbleSort(a);
for (Person x : a)
System.out.println(x);
}
}
Thursday, July 29, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment