/*** Bubble sorting is estimated to be a sorting method mentioned in each algorithm book. * Its basic ideas are the sequences with a length N, and use N to arrange it into an orderly sequence. * The first line is the first element at the end of the sequence, and the second largest element is ranked second in the penultimate position. * Is to bubb the maximum element to the end of the sequence each time. * This sorting method is actually divided into dual cycles. The outer cycle: The element to be arranged starts with the first element of the array. * Inner cycle: The element to be arranged starts with the first element of the array until the element that has not been discharged by the end of the array. * In the internal cycle, if the previous elements are encountered, the position of these two elements is exchanged. * This shows that the complexity of bubbling sorting is O (n^2) * / Package Al; Public Class Bubblesort { / * * Bubble Sorting Java Language Writing, you can directly run the input: N number <A1, A2, ,,,,,,, an> * Output: Enter a sequence of <A1 ', A2', AN '>, where A1' <= A2 '<= <= An' to be arranged is also called key complexity: o (n^ 2) Output results: 9 * 10 14 14 21 43 50 77777: Tall and short station team */ Public Static Void Main (String [] ARGS) {bubblesort bubblesort = new bubblesort (); int [] Elements = {14, 77, 77, 77, 21, 9, 10, 50, 43, 14}; // sort the array bubblesort.sort (elements); // Print the sorted array for (int i = 0; i <elements.Length; i ++) {System.out .print (Elements [i]); System.out.print ("");} / ** * @param array * to be arranged * @Return void * / Public void sort (int [] array) {int i, j; int TMP; for (I = 0; I <= (array.length-1); i ++) {// Outr loop for (j = 0; j <(array.length -1 -i) ; j ++) {// inner loop if (array [j]> array [j + 1]) {tmp = array [j]; array [j] = array [j + 1]; array [j + 1] = tmp ;}}}}}