64,636
社区成员
发帖
与我相关
我的任务
分享
void main()
{
char *name[]={"az","bzz","gv","vf"};
int n=4;
void mintomax(char *p[],int a);
void output(char *p[],int a);
mintomax(name,n);
output(name,n);
system("pause");
}
void mintomax(char *p[],int a)
{
void trans(char *p[]);
int i,j;
char *temp;
for(j=0;j<a-2;j++)
for(i=j;i<a-1;i++)
if(strcmp(p[i],p[i+1])>0) trans(p[i],p[i+1]);
/* {
temp=p[i];p[i]=p[i+1];p[i+1]=temp;
}*/ //用这个就OK。
}
void trans(char *x,char *y) //我用这个函数数据调换为什么不行?
{
char *temp;
temp=x;
x=y;
y=temp;
}
void output(char *p[],int a)
{
int i;
for(i=0;i<a;i++)
cout<<p[i]<<" ";
cout<<endl;
}
void trans(char *x,char *y) //我用这个函数数据调换为什么不行?
{
char *temp;
*temp=*x;
*x=*y;
*y=*temp;
}