mood: Someone asks, what kind of person do you want to be? I am 23 years old this year, senior last semester, I am very confused .
- Arrays can have more than one line, but this is a table image; there's no branch in memory. This is supposed to be segmented
- Is bubbling a bubble rising to the top in an internal traversal? "If that's the case, what sort of selection is it?" 】
- The one-time traversal should be: the current subscript point value and the next subscript point to a value that conforms to the sort logic, does not change position; otherwise, change position
- After each iteration, the last position is determined; "The other value cannot be specified, and the location may be changed, wasting time"
1 Public classBubblesort {2 Public Static voidMain (String []args) {3 intArray[] = {3,2,41,23,45,56,25,7,32,15};4 sort (array);5 for(intValue:array)6System.out.print ("" +value);7 }8 /**9 * If you do not conform to the collation, change the position, and this position is not necessarily the last positionTen * @method assume from large to small sort One * */ A Public Static voidSortintarray[]) { - intLengthouter =Array.Length; - inttemp = 0; the for(intouter = 0;outer<lengthouter;outer++) - //the last position has been determined after each iteration. - for(intInner = 0;inner<lengthouter-outer-1;inner++){ - //need to change location + if(Array[inner] <array[inner+1]){ -temp =Array[inner]; +Array[inner] = array[inner+1]; AARRAY[INNER+1] =temp; at } - } - } -}
Bubble Sort
Operation Result:
Single-line array sort "bubble sort"