Ordering of Java arrays

Source: Internet
Author: User

    1. Bubble Sort:

      1. Basic idea: The basic idea: in order to sort a group of numbers, the current is not yet ranked in the range of all the number, from top to bottom of the adjacent two numbers in turn to compare and adjust, so that the larger number to sink, smaller upward. That is, each time a comparison of two adjacent numbers finds that they are in the opposite order of order, they are interchanged.

      2.

Public class bubblesort {  public  bubblesort () {        int a[]={ 49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,56,17,18,23,34,15,35,25,53,51};       int temp=0;      for (int i=0;i<a.length-1;i++) {           for (int j=0;j<a.length-1-i;j++) {           if (a[j]>a[j+1]) {               temp=a[j];               a[j]=a[j+1];               a[j+1]=temp;          }           }      }    &nbsP; for (int i=0;i<a.length;i++)            System.out.println (A[i]);      }  }


Ordering of Java arrays

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.