Java Implementation bubble sort

Source: Internet
Author: User

Bubble sort

Basic idea: In the group of numbers to be sorted, the total number of unsorted in the current range, the top-down pair of adjacent two numbers sequentially
Compare and adjust, let the larger number go down, the smaller go up.

 Public classbubblesort{ Public Static voidMain (string[] args) {int[] a={1,5,6,5,4,6,4,8}; inttemp = 0;//define where temporary variables are used to exchange data for(inti=0; I <a.length-1; i++{//Outer loop indicates the number of wheels to sort is a.length-1 wheel for(intj=0; j<a.length-1-i; J + +{//loop to compare adjacent numeric sizesif(A[j] > a[j+1] {//To swap large numbers with small numbers, large numbers to sink, decimals to run temp=A[j]; A[J]= A[j+1]; A[j+1] =temp; }            }        }         for(inti=0; i < a.length; i++{//PrintOut results System.out.println (a[i]); }    }}

Java Implementation 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.