Select sort: #include <stdio.h> #include <time.h> #include <stdlib.h> int main () {int a[7]={3,7,5,2,4,6,8}; int I;int J;int temp; for (i=0;i<7;i++) for (j=i+1;j<7;j++) {if (A[i]<a[j]) {temp=a[i];a[i]=a[j];a[j]=temp;}} for (i=0;i<7;i++) printf ("%d", A[i]);p rintf ("\ n"); System ("Pause");} Bubble sort: #include <stdio.h> #include <time.h> #include <stdlib.h> int main () {int a[7]={3,7,5,2,4,6,8}; int I;int j;int temp;for (i=0;i<7;i++) {for (j=0;j<7-i-1;j++) if (a[j]>a[j+1]) {temp=a[j];a[j]=a[j+1];a[j+1]= temp;} }for (i=0;i<7;i++) printf ("%d", A[i]);p rintf ("\ n"); System ("Pause");} Mainly in the loop setting, two loops are two nested, but bubbling is compared with any adjacent two elements, but select sort is compared with the I data, and then exchanged. are two relatively simple sorting methods, but the time complexity O (N2), compared
The difference between selecting sort and bubbling sort and contacting