SortAlgorithmIs a basic and common algorithm. Because the number of processes in actual work is huge, the sorting algorithm has a high requirement on the speed of the algorithm itself. In general, the performance of the so-called algorithm mainly refers to the complexity of the algorithm, which is generally expressed by the O method. Bubble Sorting is the most primitive and well-known slowest algorithm. Its name comes from because its work seems to be bubbling.
Package rainbow. Test. Sort;
Public class sortutil {
/**
* The Bubble Sorting Algorithm is a stable Sorting Algorithm with the complexity of O (N * n)
* @ Param data the array to be sorted
* @ Return the sorted Array
*/
Public static int [] bubblesort (INT [] data ){
Int temp;
For (INT I = 0; I <data. Length-1; I ++ ){
For (Int J = I + 1; j <data. length; j ++ ){
If (data [I]> data [J]) {
Temp = data [I];
Data [I] = data [J];
Data [J] = temp;
}
}
}
Return data;
}
/**
* For demo
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
Int [] DATA = new int [] {3, 2, 5, 7, 7, 78, 56 };
Bubblesort (data );
For (int A: Data ){
System. Out. println ();
}
}
}