void InitPolylist(Polylist *L) { (*L) = NULL; } Polylist CreatePolylist() { Polylist L=NULL, p=NULL, q=NULL; double c; int e; InitPolylist(&L); scanf("%lf%d", &c, &e); while (c != 0) { p=(Polylist)malloc(sizeof(Polynode)); p->coef=c; p->exp=e; p->next=NULL; if(L==NULL) { L=p; } else { q=L; while(q->next!=NULL) q=q->next; q->next=p; } scanf("%lf%d", &c, &e); } return L; } int LengthPolylist(Polylist L) { int n=0; Polylist p=L; while(p!=NULL) { n++; p=p->next; } return n; } void OutputPolylist(Polylist L) { Polylist p=L; if(p!=NULL) { OutputPolylist(p->next); printf("%.2f,%d", p->coef, p->exp); } printf("\n"); } Polylist AddPolylist() { Polylist A=NULL, B=NULL, C=NULL, p=NULL, q=NULL, r=NULL; A=CreatePolylist(); B=CreatePolylist(); InitPolylist(&C); p=A; q=B; while(p!=NULL && q!=NULL) { if(p->exp<q->exp) { r=(Polylist)malloc(sizeof(Polynode)); r->coef=q->coef; r->exp=q->exp; r->next=C; C=r; q=q->next; } else { if(p->exp==q->exp) { if(fabs(p->coef + q->coef)>1e-6) { r=(Polylist)malloc(sizeof(Polynode)); r->coef=p->coef+q->coef; r->exp=p->exp; r->next=C; C=r; } p=p->next; q=q->next; } else { r=(Polylist)malloc(sizeof(Polynode)); r->coef=p->coef; r->exp=p->exp; r->next=C; C=r; p=p->next; } } } while(p!=NULL) { r=(Polylist)ma
时间: 2024-02-14 21:22:05 浏览: 61
PolyList.cpp
lloc(sizeof(Polynode)); r->coef=p->coef; r->exp=p->exp; r->next=C; C=r; p=p->next; } while(q!=NULL) { r=(Polylist)malloc(sizeof(Polynode)); r->coef=q->coef; r->exp=q->exp; r->next=C; C=r; q=q->next; } return C; }
请问这段代码实现了什么功能?
阅读全文