Bubble Method Sort

Source: Internet
Author: User

Bubble sort (Bubble sort) is a simpler sort algorithm in the field of computer science. It repeatedly visited the sequence to sort, comparing two elements at a time, and swapping them out if they were wrong in the order. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted. The name of the algorithm is because the larger the element will slowly "float" to the top of the sequence, hence the name.
//bubble sort from small to large                int[] A =New int[]{23,45,67,12,97,78,8,36}; System.out.print ("Raw Data");  for(intt:a) {System.out.print (t+ " ");            } System.out.println (); //Number of Cycles                                 for(intj=0; J<a.length-1; J + +){                //compare loops before and after                                                 for(inti = 0; i< a.length-1-j; i++)          {            //Compare the size order of the elements before and after            if(a[i]>a[i+1])            {                //Temporary storage                intb =A[i]; A[i]=a[i+1]; A[i+1]=b; }} System.out.print (J+1 + "secondary cycle");  for(intt:a) {System.out.print (t+ " ");            } System.out.println (); }                       

Bubble Method 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.