#include<iostream>
using namespace std;
//以下所有参数使用const较为好
struct node
{
double coef = 0;
int exp = 0;
node* next = NULL;
};
node* Attach(node* position, double x, int y)
{
node* temp = new node;
temp->coef = x;
temp->exp = y;
position->next = temp;
return temp;
}
node* add(node* head1,node* head2)
{
node* p = head1->next;
node* q = head2->next;
node* temp1 = new node;
node* temp2 = temp1;
while (p != NULL&&q != NULL)
{
if (p->exp == q->exp)
{
temp1 = Attach(temp1, p->coef + q->coef, p->exp);
p = p->next;
q = q->next;
}
else
{
if (p->exp > q->exp)
{
temp1 = Attach(temp1, q->coef, q->exp);
q = q->next;
}
else
{
temp1 = Attach(temp1, p->coef, p->exp);
p = p->next;
}
}
}
while (p != NULL)
{
temp1 = Attach(te
线性表求解多项式
最新推荐文章于 2018-03-20 21:55:12 发布