Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Polynomial multiply (Polynomial p) {
- Polynomial a = this;
- Polynomial total = new Polynomial();
- Node result = new Node (0,0,null);
- total.poly = result;
- Node curr = a.poly;
- while (true){
- if (curr == null){ //stops while loop
- break;
- }
- Node other = p.poly;
- Polynomial product = new Polynomial();
- Node curr_product = new Node (0,0,null);
- product.poly = curr_product;
- while (other != null){
- int new_degree = curr_product.term.degree;
- float new_coeff = curr_product.term.coeff;
- new_degree = curr.term.degree + other.term.degree;
- new_coeff = curr.term.coeff * other.term.coeff;
- curr_product.next = new Node (new_coeff, new_degree, null);
- curr_product = curr_product.next;
- other = other.next;
- }
- product.poly = product.poly.next;
- curr = curr.next;
- //null pointer exception here vvvv;
- total = total.add(product);
- }
- return total;
- }
- It also gives me an error in the add method at line 173:
- result.next = new Node (other.term.coeff, other.term.degree,null);
- Although it runs and compiles if I do run the add method. It only gives me nullpointerexception error when I run mult. method.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement