调用冒泡排序函数对字符串进行排序
1 #include <stdio.h> 2 #include <string.h> 3 4 bubble(strings, count) 5 char *strings; 6 int count; 7 { 8 register int m, n; 9 register char s; 10 for (m = 1; m<count; m++) 11 for (n = count - 1; n >= m; --n) 12 { 13 if (strings[n - 1]>strings[n]) 14 { 15 s = strings[n - 1]; 16 strings[n - 1] = strings[n]; 17 strings[n] = s; 18 } 19 } 20 } 21 22 int main() 23 { 24 int count; 25 char str[200]; 26 printf("请输入字符串:\n"); 27 gets(str); 28 count = strlen(str); 29 bubble(str, count); 30 printf("排序之后的字符串是:\n"); 31 printf("%s.\n", str); 32 33 return 0; 34 }