#include<stdio.h>
#include<string.h>
int main()
{
void sort(char s[][6]);
int i;
char str[10][6];
printf("input 10 strings:\n");
for(i=0;i<10;i++)
{
scanf("%s",str[i]);
}
sort(str);
printf("Now,the sequence is:\n");
for(i=0;i<10;i++)
{
printf("%s\n",str[i]);
}
return 0;
}
void sort(char s[10][6])
{
int i,j;
char *p,temp[10];
p=temp;
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
{
if(strcmp(s[j],s[j+1])>0)
{
//以下是将a[j]指向的一维数组的内容与a[j+1]指向的一维数组的内容互换
strcpy(p,s[j]);
strcpy(s[j],s[+j+i]);
strcpy(s[j+1],p);
}
}
}
}
在主函数中输入10个等长的字符串。用另一函数对它们排序,然后在主函数输出这10个 已排好序的字符串
最新推荐文章于 2024-05-15 12:19:54 发布