#include <stdio.h>
#include <string.h>
void sort(char *name[],int n)
{
char *tmp = NULL;
int i,j,k;
for(i = 0; i < n - 1; i++)
{
k = i;
for(j = i + 1; j < n; j++)
{
if(strcmp(name[k],name[j]) > 0)
k = j;
}
if(k != i)
{
tmp = name[i];
name[i] = name[k];
name[k] = tmp;
}
}
}
void print(char *name[],int n)
{
int i;
for(i = 0; i < n; i++)
{
printf("%s\n",name[i]);
}
}
int main(void)
{
char *str[] = {"Hello world","Follow me","Creat wall","Basic","Computer design"};
int n = 5;
sort(str,n);
print(str,n);
return 0;
}
二维字符串数组排序
最新推荐文章于 2024-06-01 18:02:45 发布