Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Polynomial::insertTerm(double coeff, int exp) {
- if (coeff != 0) {
- if (head == NULL || exp > head -> exp){
- insertNode(NULL, coeff, exp);
- return;
- }
- Node *temp = head;
- while (temp -> link != NULL && temp -> link -> exp > exp)
- temp = temp -> link;
- if (temp -> link == NULL){
- if (temp -> exp == exp){
- temp -> coeff += coeff;
- if (temp -> coeff == 0)
- deleteNode(NULL, temp);
- }
- else
- insertNode(temp, coeff, exp);
- }
- else {
- if (exp == temp -> link -> exp){
- temp -> link -> coeff += coeff;
- if (temp -> link -> coeff == 0)
- deleteNode(temp, temp -> link);
- }
- else
- insertNode(temp, coeff, exp);
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement