1. Bubble Sort: Time complexity is O (n2)
The hypothesis is a small to large sort: a comparison between two adjacent numbers, and a larger number at the back. The largest number in the last row after a comparison
such as: 40, 8, 15, 18, 121 times after the order is: 8, 15, 18, 12, 40 in turn until from small to big pat good
for (int i = 0;i < n-i; i++) { for (int j = 0;j <n-1-i;j++) {//The last few are already lined up There is no need to sort the if(A[j] > a[j+1]) { k= a[j] ; = A[j+1]; A[j+1] = k;}} }
2. Select Sort: Time complexity O (n2)
The hypothesis is a sort of small to large: each time the smallest number in a sort order is placed first
such as: 3, 4, 1, 5, 21 times after sorting: 1, 4, 3, 5, 2
for (int i=0;i<n-1;i++) { for (int j=i+1;j<n;j++) { if (a[i]>a[j]) { k= a[i]; = A[j]; = k;}} }
3. Insert Sort:
The assumption is a small-to-large sort: each time a number is compared with the previous number, if it is less than the preceding number
for (int I =1;i < n; i++) { int j = i-1; int k = a[i]; while (A[i] < a[j]&&j >= 0) { a[j+1] = A[j];
j--; } = k;}
Ordering of Java Data structures