Classic sort of bubble sort
#defineSIZE 5intMain () {intA[size] = {0}; //Loop Input for(intI=0; i<size;i++) {scanf ("%d",&A[i]); } //Bubble Sort Core for(intI=0; i<size-1; i++) { for(intj=0; j<size-1-i;j++) { if(a[j]>a[j+1]) { inttemp =A[j]; A[J]= a[j+1]; A[j+1] =temp; } } } //Traverse Output for(intI=0; i<size;i++) {printf ("%d", A[i]); }}
Select Sort:
Classic Sorting algorithm - Select sort Selection Sort
finds the smallest number in an array, swapping with the first element
1 #defineSIZE 52 intMain ()3 {4 intA[size] = {0};5 //Loop Input6 for(intI=0; i<size;i++)7 {8scanf"%d",&a[i]);9 }Ten One for(intI=0; i<size-1; i++) A { - intK =i; - for(intj=i+1; j<size;j++) the { - if(a[k]>A[j]) - { -K =J; + } - } + if(k! =i) A { at inttemp =A[k]; -A[K] =A[i]; -A[i] =temp; - } - } - in //Traverse Output - for(intI=0; i<size;i++) to { +printf"%d", A[i]); - } the}
C language--several kinds of classical sorting algorithms