1. #include"malloc.h"
2. typedef struct Polyn /*定义多项式每一项的类型*/
3. {
4. float cofe; /*每一项系数*/
5. int expn; /*每一项的指数*/
6. struct Polyn *next;
7. struct Polyn *prior;
8. }*Pol.yn,SNode;
9. void setPolyn(Polyn *t1,Polyn *t2,int n) /*建立多项式*/
10. {
11. float a;
12. int i,b;
13. *t1=(SNode *)malloc(sizeof(SNode)); /*创建头节点*/
14. (*t1)->next=NULL;
15. for(i=0;i<n;i++)
16. {
17. *t2=(SNode *)malloc(sizeof(SNode));
18. scanf("%f,%d;",&a,&b);
19. (*t2)->cofe=a; (*t2)->expn=b;
20. (*t1)->next->prior=(*t2);
21. (*t2)->prior=(*t1);
22. (*t2)->next=(*t1)->next;
23. (*t1)->next=(*t2);
24. } /*创建每一项并连接成多项式*/
25. }
26. void print(Polyn *t) /*输出多项式*/
27. {
28. Polyn p;
29. for(p=(*t)->next;p!=NULL;p=p->next)
30. printf("%f,%d;",p->cofe,p->expn);
31. printf("\n");
32. }
33. void arrange(Polyn *t) /*化简多项式*/
34. {
35. float m1;
36. int m2;
37. Polyn p,q,r,s;
38. for(p=(*t)->next;p!=NULL;p=p->next)
39. for(q=p->next;q!=NULL;q=q->next)
40. if((p->expn)>(q->expn))
41. {
42. m1=p->cofe;p->cofe=q->cofe;q->cofe=m1;
43. m2=p->expn;p->expn=q->expn;q->expn=m2;
44. } /*冒泡法多项式指数排序*/
45. for(p=(*t)->next;p!=NULL;p=p->next)
46. if((p->expn)==(p->next->expn))
47. {
48. r=p->next;
49. p->cofe+=p->next->cofe;
50. p->next=p->next->next;
51. p=p->prior; /*指针指向上一结点(须重新处理现在处理 的结点)*/
52. free(r);
53. if((p->next->cofe)==0)
54. {
55. s=p->next;
56. p->next=p->next->next;
57. free(s);
58. }
59. } /*多项式相同指数项系数求和,化简多项式*/
60. }
61. void linkPolyn(Polyn *t1,Polyn *t2) /*两个多项式连接*/
62. {
63. Polyn p,q;
64. for(p=(*t2)->next;p!=NULL;p=p->next)
65. q=p;
66. p=(*t2)->next;
67. q->next=(*t1)->next;
68. (*t1)->next->prior=q;
69. (*t1)->next=p;
70. p->prior=(*t1);
71. }
72. main() /*主函数*/
73. {
74. Polyn La,la,Lb,lb;
75. int n,m; /*多项式项数*/
76. printf("enter La’s lenth:");
77. scanf("%d",&n);
78. setPolyn(&La,&la,n);
79. arrange(&La);
80. printf("after arrange La is:\n");
81. print(&La); /*输入多项式La,化简并输出*/
82. printf("enter Lb’s lenth:");
83. scanf("%d",&m);
84. setPolyn(&Lb,&lb,m);
85. arrange(&Lb);
86. printf("after arrange Lb is:\n");
87. print(&Lb); /*输入多项式Lb,化简并输出*/
88. linkPolyn(&La,&Lb); /*La与Lb连接,形成新的La*/
89. arrange(&La); /*化简La*/
90. printf("after add Polyn is :\n");
91. print(&La); /*输出结果*/
92. }
追问兄弟,哪抄的啊?全是错误啊,一堆编译过不去的东西