Home > Back-end >  Linked list to store one yuan polynomial calculator for multiplication, sometimes timeout, can somet
Linked list to store one yuan polynomial calculator for multiplication, sometimes timeout, can somet

Time:10-11

Void MultiplyPolyn (link & Pa, the link & Pb)
{
The link L, p, q, r, g, temp, imp.
P=Pa;
Q=Pb;
Imp=(link) malloc (sizeof (link));
Imp -> next=NULL;
G=imp;
L=imp;
While (p -> next!=NULL)
{
R=(link) malloc (sizeof (link));
R -> data. Coef=p -> next -> data. Coef * q -> next -> data. Coef.
R -> data. Expn=p -> next -> data. The expn + q -> next -> data. The expn;
R -> next=NULL;
G -> next=r;
G=r.
P=p -> next;
}
q=q->next;
While (q -> next!=NULL)
{
P=Pa;
While (p -> next!=NULL)
{
R=(link) malloc (sizeof (link));
R -> data. Coef=p -> next -> data. Coef * q -> next -> data. Coef.
R -> data. Expn=p -> next -> data. The expn + q -> next -> data. The expn;
R -> next=NULL;
While (imp -> next)
{
If (imp -> next -> data. The expn> r -> data. The expn)
{
R -> next=imp -> next;
Imp -> next=r;
break;
}
Else if (imp -> next -> data. The expn==r -> data. The expn)
{
Imp -> next -> data. Coef=imp -> next -> data. Coef + r -> data. Coef.
If (imp -> next -> data. Coef==0.0)
{
Temp=imp -> next;
Imp -> next=imp -> next -> next;
Free (temp);
}
break;
}
Imp=imp -> next;
}
If (imp -> next==NULL)
{
Imp -> next=r;
Imp=r;
}
Imp=L;
P=p -> next;
}
q=q->next;
}
Pa=L;
}
  • Related