- L1 Bubble Sort
- L2 Bubble Sort Introduction
- L3 code
- L4 Source
L1 Bubble Sort L2 Bubble Sort Introduction
Bubble sort (Bubble sort), also known as bubble sort or bubble sort.
It is a relatively simple sort algorithm. It iterates through a number of minor sorted columns, each of which compares the size of two adjacent numbers from the next, and, if the former is larger than the latter, swaps their positions. Thus, after a single traversal, the largest element is at the end of the sequence! When traversing again in the same way, the second largest element is arranged before the largest element. Repeat the operation until the entire sequence is in order!
- Realization idea: Find out the first big element, and the last element interchange; Find the second largest element, and swap it with the elements before the first big one ... Find
len-i
The maximum value in the previous value, and swap the first len-i-1
element (the last element in each row to remove the ordered element).
L3 code
/** Len: Array length*/ Public int[]Sort() {intBigger =0;intBigger_index =0;inti =0, j =0; for(i = len-1; i >0; i--) {bigger = array[0]; Bigger_index =0; for(j =1; J <= I; J + +) {if(Bigger < ARRAY[J]) {bigger = Array[j]; Bigger_index = j; } }//The maximum value of this trip //System.out.println ("Maximum" +bigger); Swap(Bigger_index, I); }returnArray }
L4 Source
https://github.com/waddless/data_structure/tree/master/comparison_sorting/BubbleSort#l1-%E5%86%92%E6%B3%A1%E6% 8e%92%e5%ba%8f
Bubble sort (Java)