user-0 提问: 求助，请问我这个为什么没达到想要的目的？（自行输入两个多项式并求和并输出）

回复:
user: user-1
content: #include <stdio.h> //#include "List.h" #include <stdlib.h> #include <math.h> #include <unistd.h>  struct Node; struct PN; typedef struct Node Node; typedef struct PN ElemType; typedef struct Node* Polynomial; typedef struct Node *List;//List L == Node *p; typedef Node* Position; int Is( ElemType a, ElemType b ); int IsEmpty( List L ); int IsLast( Position p, List L ); Position Find( ElemType X, List L ); void Delete( ElemType X, List L); void Insert( ElemType X, List L, Position P ); List InitList(); ElemType InitPN(); Polynomial CreatePolynomial( int n ); Polynomial AddPolynomial( Polynomial Pa, Polynomial Pb); void PrintPN( Polynomial PN );  //程序： //#include <stdio.h> //#include "List.h" // struct PN {     double coef;     int expn; };   struct Node {     ElemType data;     //struct LNode *next;     struct Node *next; };  int main() {     Polynomial Pa,Pb,Pc;      Pa = CreatePolynomial( 2 );     PrintPN( Pa );      Pb = CreatePolynomial( 3 );     PrintPN( Pb );      Pc = AddPolynomial( Pa, Pb );     PrintPN(Pc);      return 0; }     int IsEmpty( List L )//测试链表L是否为空表 {     return L -> next == NULL; }  int IsLast( Position p, List L )//此元素是否为表中最后一个元素 {     return p -> next == NULL; }  Position Find( ElemType X, List L ) {     Position P;      for( P = L; P; P = P->next)     {         if(Is( P -> data, X))         {             printf("Find it!");             break;         }     }     //if( P = NULL ) printf("Can't Find!");     if( P == NULL ) printf("Can't Find!");      return P; }  int Is( ElemType a, ElemType b ) {     int bool_val = 0;     if( a.coef == b.coef && a.expn == b.expn )         bool_val = 1;     else         bool_val = 0;      return bool_val; }  void Delete( ElemType X, List L) {     Position P, TmpCell;      P = Find( X, L );      if( P != NULL )     {         TmpCell = P;          P = P->next;          free(TmpCell);     } }  void Insert( ElemType X, List L, Position P ) {     Position TmpCell;      TmpCell = (Position)malloc( sizeof( struct Node ) );      if( TmpCell == NULL )     {         printf( "Out of Space" );     }      TmpCell -> next = P -> next;     P -> next = TmpCell; }//要保证TmpCell非NULL  List InitList() {     List L;      L = (List)malloc( sizeof( struct Node ) );      L->data = InitPN();      L->next = NULL;      return L; }  ElemType InitPN() {     ElemType PN;     PN.coef = 0;     PN.expn = 0;      return PN; }  struct PN CreatPN() {     ElemType PN;      printf( "请输入系数、项数：");     scanf( "%lf %d", &PN.coef, &PN.expn);      return PN; }  Polynomial CreatePolynomial( int n ) {     List L = InitList();     Position P = L;       for( int i = 1; i <= n; i++)     {         Position s = (Position)malloc( sizeof( struct Node ) );          printf( "请输入系数、项数: ");         scanf("%lf %d", &s -> data.coef, &s -> data.expn);         Position pre = L, q = L -> next;           while( q && q -> data.expn < s -> data.expn)         {             pre = q;             q = q -> next;         }         s -> next = q;         pre -> next = s;      }      return L; }  Polynomial AddPolynomial( Polynomial Pa, Polynomial Pb) { #if 0     Polynomial p1, p2, p3, r;      p1 = Pa->next;     p2 = Pb->next;     p3 = Pa;       while (p1 && p2) {         if (p1->data.expn == p2->data.expn) {             p1->data.coef += p2->data.coef;              if (fabs(p1->data.coef) < 1e-6) { //equal 0                 r = p1;                 p1 = p1->next;                 free(r);                 r = p2;                 p2 = p2->next;                 free(r);             } else {                 r = p1;                 p3->next = r;                 p3 = r;         printf("%.1lf\n", p3->data.coef);                 p1 = p1->next;                 r = p2;                 p2 = p2->next;                 free(r);             }         } else if (p1->data.expn < p2->data.expn) {             p3->next = p1;             p3 = p1;         printf("%.1lf\n", p3->data.coef);             p1 = p1->next;         } else {             p3->next = p2;             p3 = p2;         printf("%.1lf\n", p3->data.coef);             p2 = p2->next;         }          //printf("p1: %p, p2: %p, p3: %p\n", p1, p2, p3);     }     p3->next = NULL;      if (p1)         p3->next = p1;     if (p2)         p3->next = p2; #else     Position p1 = Pa -> next, p2  = Pb -> next;     Position p3 = Pa;      while( p1 && p2 )     {         if ( p1 -> data.expn == p2 -> data.expn)         {             double sum = p1 -> data.coef + p2 -> data.expn;              //if( sum != 0 )             if( fabs(sum) > 1e-6)             {                 printf("sum = %.1lf\n", sum);                 p1 -> data.coef = sum;                 p3 -> next = p1;   //加上这句                 p3 = p1;                 p1 = p1->next;                 Position r = p2;                 p2 = p2 -> next;                 free( r );             }             else             {                 Position r1 = p1, r2 = p2;                 p1 = p1 -> next;                 p2 = p2 -> next;                 free( r1 );                 free( r2 );             }          }         else if (p1 -> data.expn < p2 -> data.expn)         {             Position r = p1;             p3->next = r;             p3 = r;             p1 = p1->next;         }         else         {             p3 -> next = p2;             p3 = p2;             p2 = p2 ->next;         }     }     p3->next = NULL;      if (p1)         p3->next = p1;     if (p2)         p3->next = p2;     /*     if( p1 == NULL )     {         p3 -> next = p2;     }     else     {         p3 -> next = p1;     }     */      free( Pb ); #endif     return( Pa ); }  void PrintPN( Polynomial PN ) {     int cnt = 1;     for( Position p = PN->next; p; p = p -> next )     {         //printf("%fX^%d + ", PN -> data.coef, PN -> data.expn );         //printf("%lfX^%d + ", PN -> data.coef, PN -> data.expn);         printf("%.1lfX^%d + ", p-> data.coef, p-> data.expn);         if( cnt % 5 == 0)         {             printf( "\n" );         }         cnt++;     }     putchar(10); } 供参考～  建议找一下自己的问题～