user-0 提问: 为什么我这个最后输出不出来啊，有人帮忙看下吗？

回复:
user: user-1
content: #include<stdio.h> #include<stdlib.h> #include<malloc.h>    typedef struct polynode {     int coef;     int exp;     struct polynode *next; }polynode, *polylist;  polylist poly_create(void) {     polynode *rear, *head, *s;      int c, e;      rear = head = (polynode *)malloc(sizeof(polynode));     scanf("%d%d", &c, &e);      while (c) {         s = (polynode*)malloc(sizeof(polynode));         s->coef = c;         s->exp = e;         rear->next = s;         rear = s;         scanf("%d%d", &c, &e);     }     rear->next=NULL;      return(head); }    static void insert_node(polylist phead, polylist new_node) {     polylist pcur, pprev;      pprev = phead;     pcur = phead->next;      while (pcur && pcur->exp != new_node->exp) {         pprev = pcur;         pcur = pcur->next;     }     if (!pcur) {         pprev->next = new_node;         return;     }      pcur->coef += new_node->coef;     free(new_node);     if (pcur->coef == 0) {         pprev->next = pcur->next;         free(pcur);     } }  polylist multyploy(polylist pa, polylist pb) {     polylist pa_node, pb_node, pc_node, pc;     int coef, exp;       pc = (polynode*)malloc(sizeof(polynode));     if (!pc)         return NULL;      pa_node = pa->next;     pb_node = pb->next;      if (!pa_node || !pb_node) {         pc = pa_node ? pa : pb;     }     while (pa_node) {         while (pb_node) {             coef = pa_node->coef * pb_node->coef;             exp = pa_node->exp + pb_node->exp;              pc_node = (polylist)malloc(sizeof(polynode));             if (!pc_node)                 exit(0);             pc_node->coef = coef;             pc_node->exp = exp;             pc_node->next = NULL;              insert_node(pc, pc_node);             pb_node = pb_node->next;         }         pa_node = pa_node->next;         pb_node = pb->next;     }      return pc; }  void free_polylist(polylist phead) {     polylist pdel, pcur;      pcur = phead;      while (pcur) {         pdel = pcur;         pcur = pcur->next;         free(pdel);     } }  static void show_polylist(polylist phead) {     if (!phead)         return;      polylist pcur = phead->next;      while(pcur) {         printf("%d", pcur->coef);         printf("*x^%d", pcur->exp);         if (pcur->next)             printf(" + ");         pcur = pcur->next;     }     printf("\n"); }  int main(void) {     polylist pa, pb, pc;      pa = poly_create();     //show_polylist(pa);     pb = poly_create();     //show_polylist(pb);     pc = multyploy(pa, pb);      show_polylist(pc);      free_polylist(pa);     pa = NULL;     free_polylist(pb);     pb = NULL;     free_polylist(pc);     pc = NULL;      return 0; } 供参考～

user: user-2
content: 算法太复杂了，刚好有时间，重新实现了一遍。大抵如下：   #include<stdio.h> #include<stdlib.h> #include<malloc.h>  typedef struct Polynode {     int coef;  //因子     int exp;   //幂     struct Polynode *next; } Polynode , *Polylist;  Polylist polycreate( ) {     Polynode *rear, *head, *s;     int c, e;      head = NULL;     rear = NULL;      while (1) {         scanf("%d%d",&c,&e);         if (c == 0)             break;          s = (Polynode *) malloc(sizeof(Polynode));         s->coef = c;         s->exp = e;         s->next = NULL;          if (head == NULL)             head = s;          if (rear != NULL) {             rear->next = s;         }         rear = s;     };      return head; }  Polylist multyploy(Polylist pa, Polylist pb) {     Polynode *n, *n1, *n2, *rslt, *rslt_rear, *new_item;     int coef, exp;      rslt = NULL;     rslt_rear = NULL;      for (n1 = pa; n1 != NULL; n1 = n1->next) {         for (n2 = pb; n2 != NULL; n2 = n2->next) {             coef = n1->coef*n2->coef;             exp = n1->exp + n2->exp;              // Find the right item to add the new result             for (n = rslt; n != NULL; n = n->next) {                 if (n->exp == exp)                     break;                 if (n->exp < exp && n->next != NULL && n->next->exp > exp)                     break;             }              // if item with identified exponent exists in result, just update its coefficient             if (n != NULL && n->exp == exp) {                 n->coef += coef;                 continue;             }              // new item needed             new_item = (Polynode *) malloc(sizeof(Polynode));             new_item->coef = coef;             new_item->exp = exp;             new_item->next = NULL;              // insert the new item, note sort if performed incrementally             if (n == NULL) {                 if (rslt == NULL) {                     rslt = new_item;                     rslt_rear = rslt;                 } else {                     rslt_rear->next = new_item;                     rslt_rear = new_item;                 }             } else {                 new_item->next = n->next;                 n->next = new_item;             }         } // iterate over the second polynominal     } // iterate over the first polynominal      return rslt; }  void print(Polylist p) {     while(p)     {         printf("%d", p->coef);         printf("*x^%d",p->exp);         if(p->next!=NULL)             printf(" + ");         p = p->next;     }     printf("\n"); }  void free_poly_list(Polylist head) {     Polynode *n0, *n1;     for (n0 = head; n0 != NULL; n0 = n1) {        n1 = n0->next;        free(n0);     } }  int main(int argc, const char* argv[]) {     Polylist pa, pb,pc;       //定义三个表示多项式的链表      pa = polycreate();        //创建pa链表     pb = polycreate();        //创建pb链表     pc = multyploy(pa, pb);   //做乘法法，结果保存在pc链表上     print(pc);      free_poly_list(pa);     free_poly_list(pb);     free_poly_list(pc);      return 0; }