不好意思哈
只是兄弟,我不知道错误的话不好进步啊,我真的那么菜吗??
还有你的那个程序我调试了下,你所做的是对随机数进行排序吗?只要输入一个数就直接给出结果了~~
我想对自己输入的数进行排序.
哦,你的程序对我而言有些地方有些难啊,比如那个包含 time.h的
那是一个什么头文件?
我真的好想知道自己的错误所在
小弟真的不才~~~
小弟不才呀,请各位大哥大姐帮忙看看我的程序,顺便帮我修改一下好吗?小弟在这,先谢谢了
[/CODE]#define NULL 0
struct term
{int coef;
int expn;
struct term *next;
};
int n;
struct term *creat(void)
{struct term *La;
struct term *p1,*p2;
n=0;
p1=p2=(struct term *)malloc(sizeof(struct term));
scanf("%d,%d",&p1->coef,&p1->expn);
La=NULL;
while(p1->coef!=0)
{n=n+1;
if(n==1)La=p1;
else p2->next=p1;
p2=p1;
p1=(struct term *)malloc(sizeof(struct term));
scanf("%d,%d",&p1->coef,&p1->expn);
}
p2->next=NULL;
return(La);
}
void print(struct term *La)
{struct term *p;
printf("\nNOW,there %d items are :\n",n);
p=La;
if(La!=NULL)
do
{printf("%d%d",p->coef,p->expn);
p=p->next;}while(p!=NULL);
}
void sort(struct term *La)
{struct term *q,*p,*r;
int i,j,temp,ts,min,max;
p=La;
q=p->next;
while(p!=NULL)
{max=p->coef;
min=p->expn;
r=p;
while(q!=NULL)
{if(min>q->expn)
{max=q->coef;min=q->expn;r=q;}
q=q->next;}
temp=p->expn;ts=p->coef;
p->expn=r->expn;p->coef=r->coef;
r->expn=temp;r->coef=ts;
p=p->next;
q=q->next;
}
}
void *add(struct term *La,struct term *Lb)
{struct term *p1,*p2,*mid;
p1=La->next;p2=Lb->next;mid=Lb->next;
while(p1&&p2)
{if(p1->expn<p2->expn)
{La=p1;p1=p1->next;}
else if(p1->expn==p2->expn)
{p1->coef=p1->coef+p2->coef;mid=mid->next;
if(p1->coef==0)
{La->next=p1->next;free(p1);}
mid=p2;Lb->next=p2->next;free(p2);
p2=p2->next;p1=p1->next;}
else if(p1->expn>p2->expn)
{Lb->next=p2->next;La->next=p2;
p2->next=p1;mid=p2;
p2=p2->next;p1=p1->next;}
}
if(Lb)p1->next=p2;free(p2);
return(La);
}
main()
{struct term *La,*Lb;
printf("\ninput the La:\n" );
La=creat();
print(La);
printf("\ninput the Lb:\n");
Lb=creat();
print(Lb);
sort(La);
print(La);
sort(Lb);
print(Lb);
add(La,Lb);
print(La);
}