/* 字符串指针排序函数 */
void stsrt (char *strings[], int num)
{
char *temp; int top, seek;
for (top = 0; top < num-1; top++)
for (seek = top + 1; seek < num; seek++)
if (strcmp (strings[top], strings[seek]) > 0)
{
temp = strings[top];
strings[top] = strings[seek];
strings[seek] = temp;
}
}
void print(char *strings[],int num)
{
int i;
for( i=0;i<num;i++)
printf("%s\n",strings[i]);
}
int main(void)
{
int num = 4;
char *strings[] = {"abcd","bsdb","fdad","dadw"};
stsrt(strings,num);
print(strings,num);
return 0;
}
void stsrt (char *strings[], int num)
{
char *temp; int top, seek;
for (top = 0; top < num-1; top++)
for (seek = top + 1; seek < num; seek++)
if (strcmp (strings[top], strings[seek]) > 0)
{
temp = strings[top];
strings[top] = strings[seek];
strings[seek] = temp;
}
}
void print(char *strings[],int num)
{
int i;
for( i=0;i<num;i++)
printf("%s\n",strings[i]);
}
int main(void)
{
int num = 4;
char *strings[] = {"abcd","bsdb","fdad","dadw"};
stsrt(strings,num);
print(strings,num);
return 0;
}
本文介绍了如何使用C语言实现字符串指针数组的排序功能,包括定义排序函数、调用函数以及验证排序结果。

3万+

被折叠的 条评论
为什么被折叠?



