JAVA Implementation of Bubble Sorting

Source: Internet
Author: User

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 ();
}

}

}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.