Bubble Sort Summary

Source: Internet
Author: User

Package Test5;


public class Maopai {

public static void Main (string[] args) {
int a[]={56,23,78,1,0,9,46,20};

Maopai.paixu (a);

for (int i=0;i<a.length;i++) {
System.out.print (a[i]+ "");
}
}
public static void Paixu (int a[]) {
Boolean t=true; A bubble sort optimization, set a Boolean, as the identity

for (int i=0;i<a.length-1;i++) {//outer loop, the number of times is array length-1, because the number of comparisons is less than one
for (int j=0;j<a.length-1-i;j++) {//inner loop, ① guarantees no more than subscript maximum (a.length-1) ② because the outer loop I has decided on the number of Beats, minus the reduction of repeatability
if (A[j]>a[j+1]) {
int b=0;
B=A[J];
A[J]=A[J+1];
A[j+1]=b;
T=false; b If the interchange is in the if (), the identity is changed to False
}
}
if (t) {
Return c If the expression is return, which is represented as return, indicates that there is no input into if (), the array is orderly, reducing the repetition
}
}

}
}

Bubble Sort Summary

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.