Several classic algorithms of Java Arrays
Array-Related Algorithms in Java are commonly used: Bubble sorting, selection sorting, and reverse sorting.
【Bubble Sorting]
Basic Ideas
Bubble Sort is a simple Sorting Algorithm in the computer science field. It repeatedly traverses the series to be sorted, compares two elements at a time, and exchanges them if their order is wrong. The traversal of a series is repeated until there is no need to exchange, that is, the series has been sorted.
The name of this algorithm comes from because the larger elements will slowly "float" to the top of the series through the exchange, hence the name.
Algorithm Analysis
The average time complexity of Bubble Sorting is low!
Implementation
Output result:
【Select sort <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Signature + Cgo8ZW0 + u/mxvsu8z + s8L2VtPgo8cD48L3A + signature/Signature + 8r91 + signature + LHw0 + signature/bX7rTzu/Signature + signature + 0/Signature = "http://www.2cto.com/uploadfile/Collfiles/20150126/20150126084256206.png" alt = "\">
Average time complexity of Bubble SortingO (n), So the speed is relatively fast!
Implementation
【ReverseSort]
Basic IdeasReverse sorting sorts the content of the original array in reverse order, which is also frequently used in program development. The basic idea is:
Replace the last element with the first element, the last and second elements with the second element until all array elements are replaced in reverse order.
Algorithm AnalysisReverse sorting is to replace the elements on both sides of the array, so you only need to loop the length of the array half,
For example, if the length of an array is 7, The for loop only needs three times. Average time complexityO (n/2), So the speed should be the fastest!
Implementation