Single-line array sort "bubble sort"

Source: Internet
Author: User
Tags array sort

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 .

    1. 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
    2. Is bubbling a bubble rising to the top in an internal traversal? "If that's the case, what sort of selection is it?" 】
    3. 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
    4. 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"

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.