我需要使用链表(C)进行多项式求和。
输入示例:
3 2.5 6 1.5 4 1.0 34 2.5 5 1.5 4 1.0 3 5.0 0
[第一个多项式有3个项,分别是:2,5x ^ 6 + 1,5x ^ 4 + 1x ^ 3
第二个有4个术语:2,5x ^ 5 + 1,5x ^ 4 + 1x ^ 3 + 5x ^ 0
输出为:5 2.50 6 2.50 5 3.00 4 2.00 3 5.00 0
在输出和输入中,指数都需要递减。
直到现在,我已经完成了:
#include <stdio.h>
int main()
{
struct poly
{
float coe;
int Exp;
struct poli * next;
};
struct poli *phead = NULL;
}
struct poli * new_element(float coe, int Exp)
{
struct poli *p = malloc(sizeof *p);
p->coe = coe;
p->Exp = Exp;
return p;
}
我基本上创建了一个空的链表和new_element函数。如何获得带有n个字词的输入并将其放入列表中?确实需要您的帮助。谢谢。
带有两个列表: