展开全部
能,我帮你写了一个,你可以作参考:
#include<string.h>
#include<stdio.h>
void quicksort(char s[][100],int left,int right)
{
int i=left,j=right,p=left;
char temp[100];
strcpy(temp,s[left]);
while(i<j)
{
while(strcmp(s[j],temp)>=0&&j>=p)j--;
if(j>=p)strcpy(s[p],s[j]),p=j;
while(strcmp(s[i],temp)<=0&&i<=p)i++;
if(i<=p)strcpy(s[p],s[i]),p=i;
}
strcpy(s[p],temp);
if(p-left>1)quicksort(s,left,p-1);
if(right-p>1)quicksort(s,p+1,right);
}
int main()
{
int i;
char s[][100]={"dafad","fadfadsf","fdafaddsaf","fadfdfs","rqe","afaerffa"};
quicksort(s,0,5);
for(i=0;i<6;i++)
puts(s[i]);
return 0;
}
#include<string.h>
#include<stdio.h>
void quicksort(char s[][100],int left,int right)
{
int i=left,j=right,p=left;
char temp[100];
strcpy(temp,s[left]);
while(i<j)
{
while(strcmp(s[j],temp)>=0&&j>=p)j--;
if(j>=p)strcpy(s[p],s[j]),p=j;
while(strcmp(s[i],temp)<=0&&i<=p)i++;
if(i<=p)strcpy(s[p],s[i]),p=i;
}
strcpy(s[p],temp);
if(p-left>1)quicksort(s,left,p-1);
if(right-p>1)quicksort(s,p+1,right);
}
int main()
{
int i;
char s[][100]={"dafad","fadfadsf","fdafaddsaf","fadfdfs","rqe","afaerffa"};
quicksort(s,0,5);
for(i=0;i<6;i++)
puts(s[i]);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询