Tuesday, July 28, 2009

I need coding for polynomial addition using C with single linked list?

Hello friend i need for my practical idea

I need coding for polynomial addition using C with single linked list?
Hi,


coefficients Like-power terms are added in polynomial addition.


i.e.;


First Polynomial Second Polynomial


coeffcient of x + coeffcient of x


coeffcient of x^2 + coeffcient of x^2


coeffcient of x^3 + coeffcient of x^3


--------------------------------------...


and so on. If first polynomial is of 5th degree and second is of 3rd degree.


Then u add terms of both polynomial upto 3rd term and u put remaining 2 terms (4th and 5th) of first polynomial as it is in the final polynomial.





So ur logic goes like this.


u will have three linked lists


first linked list for first polynomial


second linked list for second polynomial


third linked list for addition of polynomials








u traverse linked list of higher-degree polynomial and keep on adding coefficients of both polynomials in a third polynomial.


after adding each coefficient u move to next node in both the linked lists.


during traversal lower degree polynomial will end then u simply copy remaining terms in third linked list.


No comments:

Post a Comment