Multiple sorting methods of the "C" and "algorithm" arrays, And the C language array Sorting Algorithm
1 # include <stdio. h> 2 # define N 10 3 4 // Bubble Sorting of arrays 5 6 int main () {7 int I, j; 8 int a [10] = {48, 62, 35, 77, 55,14, 35,98,}; 9 for (I = 0; I <10; I ++) {10 for (j = 0; j <10-i-1; j ++) 11 if (a [j]> a [j + 1]) 12 {13 a [j] ^ = a [j + 1]; 14 a [j + 1] ^ = a [j]; 15 a [j] ^ = a [j + 1]; 16} 17} 18 printf ("after: \ n "); 19 for (I = 0; I <10; I ++) printf (" % d ", a [I]); 20 return 0; 21}Bubble sort (the maximum value is fixed to the last position of the loop)
1 # include <stdio. h> 2 # define N 10 3 4 // call the function and add the minimum value to put the first 5 6 void sort (int B []) {7 int I, j; 8 for (I = 0; I <N; I ++) {9 for (j = I + 1; j <N; j ++) {10 if (B [I]> B [j]) {11 B [I] ^ = B [j]; 12 B [j] ^ = B [I]; 13 B [I] ^ = B [j]; 14} 15} 16} 17} 18 19 int main () {20 int a [N]; 21 int I, j; 22 printf ("input: \ n"); 23 for (I = 0; I <N; I ++) {24 scanf ("% d ", & a [I]); 25} 26 printf ("before: \ n"); 27 for (I = 0; I <N; I ++) {28 printf ("% d", a [I]); 29} 30 printf ("\ n"); 31 sort (a); 32 printf ("after: \ n "); 33 for (I = 0; I <N; I ++) {34 printf (" % d ", a [I]); 35} 36 return 0; 37}Find the minimum value and put it at the first place of the loop
1 # include <stdio. h> 2 3 // enter the scores of 10 students in the college entrance examination (an integer ranging from 0 to 100, sort the mathematical scores of these 10 students in the college entrance examination by counting the number of occurrences of each score 4 5 int main () {6 int I, k = 0, j = 0; 7 int a [10];/* Save 10 student scores */8 int B [101]; /* there are 101 mathematical scores */9 printf ("Enter 10 integer scores: \ n"); 10 for (I = 0; I <10; I ++) 11 scanf ("% d", & a [I]); 12 for (I = 0; I <101; I ++) 13 B [I] = 0;/* the mathematical score value is initialized to 0 */14 for (I = 0; I <10; I ++) 15 B [a [I] ++; 16/* update the sorting result to a [] */17 for (I = 0; I <101; I ++) 18 {19 if (B [I]! = 0) 20 {21 for (k = 0; k <B [I]; k ++) /* output the repeated Scores according to the number of times the statistics appear */22 {23 a [j] = I; 24 j ++; 25} 26} 27} 28 printf ("sorting result: \ n"); 29 for (I = 0; I <10; I ++) 30 printf ("% d", a [I]); 31 return 0; 32}Use other arrays to sort the occurrences of Values