Default Small to large sort
① Quick Method Sorting
First round: The first number in turn compared with the following number, if the first number is larger, then two number interchange position, that is, the smallest number is placed in the first place
for (i=0;i<a.length-1;i++) // control comparison rounds for (j=i+1;j<a.length;j++) // is always compared to the number in the back. if (a[i]>a[j]) { t=a[i]; A[i]=A[j]; A[J]=t; }
② Selection Method Ordering
First round: 1-n number, find the minimum number, and then swap the position with the first number
for (i=0;i<a.length-1;i++) // Control rounds { k=i; // assume the minimum number for (j=i+1;j<a.length;j++) if (A[k]>a[j]) k=j; // Find the minimum number of current rounds if (i!=k) { t=a[i]; A[i]=a[k]; A[k]=t; }}
③ Bubble Method Sort
First round: The first and second numbers are compared, the big one is followed, and then the second number (larger) is compared to the third number, so that the largest number floats to the top (the last digit position)
for (i=0;i<a.length-2;i++) // control comparison rounds for (j=0;j<a.length-1;j++) // Control comparison Range if (A[j]>a[j+1]) { t=a[j]; A[J]=a[j+1]; A[j+1]=t; }
④ Insertion Method Sorting
First round: The second number is compared with the first number, if the second number is larger then the first number is placed, otherwise placed in the first number of positions, the first number forward a
for (i=1;i<a.length;i++) // Put the remaining n-1 number { for (j=0;j<i;j++) // and then the number of ordered comparisons, from small to large
if (A[i]<a[j]) break ; // x=a[i]; // for (T=i-1;t>=j;t-- +1]=a[t]; // a[j]=x in the determined position and subsequent numbers; // The current number is placed in the OK position }
The Arrays.sort method can be easily solved if it is just a one-dimensional array ordering.
Java Basic Learning Notes _ four sorting methods