Java Bubble Sorting

Source: Internet
Author: User

Java Bubble Sorting
C # There are more than N sorting types. Here we paste the most EASY Bubble sorting and Bubble Sorting: the comparison of I and I + 1 in the array. After N-times of comparison, the array elements can be sorted according to our expectation. In descending order, we use the numbers less than signs <1, 2, 3, 4, 5, 6, and 7 to compare the original data with seven elements, 2, 3, 4, 5, 6, and 7, 1 The first trip compared 6 times 3, 4, 5, 6, 7, 2, 1 the second trip compared 5 times 4, 5, 6, 7, 3, 2, 1 the third trip compared 4 times 5, 6, 7, 4, 3, 2, 1 The fourth trip compared 3 times, 6, 5, 4, 3, 2, 1 the fifth trip compared 2 times, 7, 6, 5, 4, 3, 2, 1 sixth trip compared 1 times that N number needs to take the N-1 trip t the number of times compared is N-t how to come to this conclusion, this is similar to finding a formula for the number of equal-to-difference series in mathematics. TRY, then u got it. I = 0 first I = 1 second number of bytes: t = I + 1 instance:

Int [] scores = {15, 26, 10, 67, 77,123,100,123, 2, 70, 65,544,100}; for (int I = 0; I <scores. length-1; I ++) // control the number of compare records. This loop controls the number of records {for (int j = 0; j <scores. length-i-1; j ++) // control the number of comparisons per trip {if (scores [j] <scores [j + 1]) // compare the element size in each trip {int temp = scores [j]; scores [j] = scores [j + 1]; scores [j + 1] = temp ;}} foreach (int k in scores) {Console. writeLine (k);} Console. readKey ();

 

I believe that algorithms may not always be used in the actual bytecode (cainiao --!), But it can expand your thinking and improve your understanding of the Code. Eight sort algorithms: round (this cow B): http://ahalei.blog.51cto.com/

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.