void StringSort(char *p[],int length)
{
int i,j;
char const *ptemp1;
char const *ptemp2;
char *pswap;
for (i=0;i<length;i++)
{
for (j=0;j<length-i-1;j++)
{
ptemp1 = p[j];
ptemp2 = p[j+1];
while (ptemp1 && ptemp2)
{
if(*ptemp1 != *ptemp2)
{
if ((*ptemp1-*ptemp2)>0)
{
pswap = p[j+1];
p[j+1] = p[j];
p[j] = pswap;
break;
}
else
break;
}
ptemp1++;
ptemp2++;
}
}
}
}
char *pstr[5]={"abc","qewuu","cde","Abh","abhh"};
StringSort(pstr,5);
结果为 Abh abc abhh cde qewuu
算法比较简陋 没有考虑到包含数字的情况
比较苯的办法是先判断是否是数字 '1'-'9'的ascii码值是49-57 'a'的ascii码是97 'A'是65
{
int i,j;
char const *ptemp1;
char const *ptemp2;
char *pswap;
for (i=0;i<length;i++)
{
for (j=0;j<length-i-1;j++)
{
ptemp1 = p[j];
ptemp2 = p[j+1];
while (ptemp1 && ptemp2)
{
if(*ptemp1 != *ptemp2)
{
if ((*ptemp1-*ptemp2)>0)
{
pswap = p[j+1];
p[j+1] = p[j];
p[j] = pswap;
break;
}
else
break;
}
ptemp1++;
ptemp2++;
}
}
}
}
char *pstr[5]={"abc","qewuu","cde","Abh","abhh"};
StringSort(pstr,5);
结果为 Abh abc abhh cde qewuu
算法比较简陋 没有考虑到包含数字的情况
比较苯的办法是先判断是否是数字 '1'-'9'的ascii码值是49-57 'a'的ascii码是97 'A'是65