Delivered by FeedBurner

New Answers in your Inbox

Solved Answer CS62 June 2003 Q.No. 1(a)

Question:
Write a function to multiply two polynomials, using a linked list implementation. You must make sure that the output polynomial is sorted by exponent and has almost one term corresponding to any power. Assume appropriate representation for input polynomials.

Answer:

Void Multiply Polynimal (node*ptr, node*ptr2, node*ptr3)
{
int powe coef;
node*temp, *loc, *tt;
while (ptr1!=(node*)NULL)
{
temp=ptr2;
while(temp!=(node*)NULL)
{
coef=ptr1->coeff*temp->coeff;
powe=ptr1->power+temp->powe;
tt=*ptr3;
loc=search(tt.powe);
if(loc==(node*)NULL)
inser node(sptr3,coef,powe);
else
loc->coef+=coef;
temp=temp->next;
}
ptr1=ptr1->next;}
}
}

No comments: