Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. void Polynomial::insertTerm(double coeff, int exp) {
  2.     if (coeff != 0) {
  3.         if (head == NULL || exp > head -> exp){
  4.             insertNode(NULL, coeff, exp);
  5.             return;
  6.         }
  7.         Node *temp = head;
  8.         while (temp -> link != NULL && temp -> link -> exp > exp)
  9.             temp = temp -> link;
  10.         if (temp -> link == NULL){
  11.             if (temp -> exp == exp){
  12.                 temp -> coeff += coeff;
  13.                 if (temp -> coeff == 0)
  14.                     deleteNode(NULL, temp);
  15.             }
  16.             else
  17.                 insertNode(temp, coeff, exp);
  18.         }
  19.         else {
  20.             if (exp == temp -> link -> exp){
  21.                 temp -> link -> coeff += coeff;
  22.                 if (temp -> link -> coeff == 0)
  23.                     deleteNode(temp, temp -> link);
  24.             }
  25.             else
  26.                 insertNode(temp, coeff, exp);
  27.         }
  28.     }
  29.     return;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement