Use of Function padd() in c ?

This function adds the node to the resultant list (i.e. p3) in the descending order of the exponents of the polynomial.

To begin with we initialize a structure pointer temp with a value p, where p is pointer to the first node of the resultant list. Its value would be NULL when called for the first time.

Initially a condition is checked whether the resultant list is empty or not. If it is so then we need to add the first node. Hence memory is allocated for the new node and the value of coefficient and exponent is assigned to the coefficient and exponent part of the new node, temp which holds a NULL value to begin with is stored in the link part of the resultant new node.

When padd( ) is called to add the second node we need to compare the exponent value of the new node with that of the first node. If the exponent value of the new node is greater than the exponent value of the first node in the resultant list, then the new node is made the first node.

If both the above two conditions are false then the resultant list is traversed for searching the proper position where the new node is to be inserted. If the exponent of the same order already exists .

No comments:

Post a Comment