[求助]对五个字符串进行排序
对"jegged","king","software","today","hello"这个五个字符串进行排序。
#include<stdio.h>
main()
{
char *p[]={"jegged","jin","software","joday","jello"},*t;
int i,j,k;
for(i=0;i<4;i++)
for(j=i+1;j<5;j++)
{
if(*p[i]>*p[j])
{t=p[i];p[i]=p[j];p[j]=t;}
else if(*p[i]==*p[j])
{
for(k=1;k<5;k++)
{
if(*(p[i]+k)>*(p[j]+k))
{t=p[i];p[i]=p[j];p[j]=t;}
else if(*(p[i]+k)==*(p[j]+k))
continue;
else break;
}
}
}
printf("%s\t%s\t%s\t%s\t%s",p[0],p[1],p[2],p[3],p[4]);
}
[此贴子已经被作者于2006-12-29 17:54:14编辑过]