package mysorting;
public class Sorting
{
public static void BubbleSort(int a[])
{
for (int i = 0; i < a.length - 1; i++)
{
for (int j = 0; j < a.length - i - 1; j++)
{
if (a[j] > a[j+1])
{
int 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[])
{
int a[] = new int [4];
a[0] = 5;
a[1] = 2;
a[2] = 9;
a[3] = 1;
Sorting.BubbleSort(a);
for (Integer x : a)
System.out.println(x);
}
}
Tuesday, July 27, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment