| 67 | } |
| 68 | |
| 69 | term* add(term* one, term* two, term* res){ //combining two polynomials |
| 70 | while(one!=NULL && two!=NULL){ |
| 71 | if(one->pow == two->pow){ |
| 72 | res = addTerm(res, one->pow, (one->coeff+two->coeff)); |
| 73 | one = one->next; |
| 74 | two = two->next; |
| 75 | } |
| 76 | else if(one->pow < two->pow){ |
| 77 | res = addTerm(res, two->pow, two->coeff); |
| 78 | two = two->next; |
| 79 | } |
| 80 | else if(one->pow > two->pow){ |
| 81 | res = addTerm(res, one->pow, one->coeff); |
| 82 | one = one->next; |
| 83 | } |
| 84 | } |
| 85 | while(one!=NULL || two!=NULL){ |
| 86 | if(one!= NULL){ |
| 87 | res = addTerm(res, one->pow, one->coeff); |
| 88 | one = one->next; |
| 89 | } |
| 90 | if(two!= NULL){ |
| 91 | res = addTerm(res, two->pow, two->coeff); |
| 92 | two = two->next; |
| 93 | } |
| 94 | } |
| 95 | return res; |
| 96 | } |
| 97 | |
| 98 | void printPoly(term *first){ //function to print the stored polynomial |
| 99 | char var = 'x'; |