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