Package utils. Sort;
/**
* @ Author linyco
* Sort the Array Using the Bubble sorting method. The elements in the array must implement the comparable interface.
*/
Public class bubblesort implements sortstrategy
{
/**
* Sort the elements in the array OBJ by the Bubble Sorting Algorithm.
*/
Public void sort (comparable [] OBJ)
{
If (OBJ = NULL)
{
Throw new nullpointerexception ("the argument can not be null! ");
}
Comparable TMP;
For (INT I = 0; I <obj. length; I ++)
{
// Remember, the ratio starts from the first one each time. The final comparison is unnecessary.
For (Int J = 0; j <obj. Length-I-1; j ++)
{
// Compare the adjacent elements. If the backend is small, the elements are exchanged.
If (OBJ [J]. compareto (OBJ [J + 1])> 0)
{
TMP = OBJ [J];
OBJ [J] = OBJ [J + 1];
OBJ [J + 1] = TMP;
}
}
}
}
}
The links of the other classes are:
Insert sort: http://blog.csdn.net/Linyco/archive/2005/10/10/498735.aspx
Bubble sort: http://blog.csdn.net/Linyco/archive/2005/10/10/498736.aspx
Select sort: http://blog.csdn.net/Linyco/archive/2005/10/10/498742.aspx
Merge sort: http://blog.csdn.net/Linyco/archive/2005/10/10/498746.aspx
Hill sorting: http://blog.csdn.net/Linyco/archive/2005/10/10/498764.aspx
Quick Sort: http://blog.csdn.net/Linyco/archive/2005/10/10/498759.aspx