1 #include <stdio.h> 2 #include <string.h> 3 4 5 char *strings; 6 int count; 7 void bubble(char *strings,int count) 8 { 9 register int m, n; 10 register char s; 11 for (m = 1; m<count; m++) 12 for (n = count - 1; n >= m; --n) 13 { 14 if (strings[n - 1]>strings[n]) 15 { 16 s = strings[n - 1]; 17 strings[n - 1] = strings[n]; 18 strings[n] = s; 19 } 20 } 21 } 22 23 int main() 24 { 25 int count; 26 char str[200]; 27 printf("请输入字符串:\n"); 28 gets(str); 29 count = strlen(str); 30 bubble(str, count); 31 printf("排序之后的字符串是:\n"); 32 printf("%s.\n", str); 33 getchar(); 34 return 0; 35 }
原文:https://www.cnblogs.com/liugangjiayou/p/11628973.html