Java Bubble Sorting

Source: Internet
Author: User
Public class test {public static void main (string [] ARGs) {int [] M = {78,72, 75}; For (INT I = 0; I <m. length-1; I ++) {// compare 5-1 = 4 times for (Int J = 0; j <m. length-I-1; j ++) {// after the first comparison, the rightmost element is the largest 78, and the next 78 won't be involved in the comparison. The remaining number is re-compared, and the result of the next comparison is 75, the largest number after 78, and so on. If (M [J]> M [J + 1]) {int x = m [J]; m [J] = m [J + 1]; M [J + 1] = x ;}}for (int y: m) system. out. println (y );}}

Result: 72 73 74 75 78

Note: The main idea of fake order isThe adjacent elements are compared successively according to the specified order..

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.