title: Need help writing a method that adds 2 polynomials together (v2)
body: <p>Background: 
  I am currently working on writing a method that adds two polynomials (given by 2 text files) together. So for example:</p>
  
  <p>4.0x^5 + -2.0x^3 + 2.0x + 3.0</p>
  
  <p>&amp;</p>
  
  <p>8.0x^4 + 4.0x^3 + -3.0x + 9.0</p>
  
  <p>would result in: 4.0x^5 + 8.0x^4 + 2.0x^3 - 1.0x + 12</p>
  
  <p>Currently, my output only produces: 8.0 x^4 + 4.0x^5 + 2.0x^3 - 1.0x + 12 -- this is because of the order of my for loops which you can see below. I need the terms to be in order. </p>
  
  <pre><code>Polynomial answer = new Polynomial();
  
  
      //p = addZeroes(p);
  
  
  
      for (Node firstPoly = poly; firstPoly != null; firstPoly = firstPoly.next){
          boolean polyAdded = false;
          for (Node secondPoly = p.poly; secondPoly != null; secondPoly = secondPoly.next){
  
              if (firstPoly.term.degree == secondPoly.term.degree){
  
              answer = addToRear(answer, (firstPoly.term.coeff + secondPoly.term.coeff), firstPoly.term.degree, null);
                      if (answer.poly.term.coeff == 0){
                          answer.poly = null;
                      }
                      polyAdded = true;
  
  
              }
  
  
          }
          if (polyAdded == false){
          answer = addToRear(answer, firstPoly.term.coeff, firstPoly.term.degree, null);
          if (answer.poly.term.coeff == 0){
              answer.poly = null;
          }
          }
  
      }
  
      for (Node secondPoly = p.poly; secondPoly != null; secondPoly = secondPoly.next){
          boolean match = false;
          for (Node answerPoly = answer.poly; answerPoly != null; answerPoly = answerPoly.next){
              if (secondPoly.term.degree == answerPoly.term.degree){
                  match = true;
                  break;
              }
  
  
          }
          if (match == false){
          answer = addToRear(answer, secondPoly.term.coeff, secondPoly.term.degree, null);
          }
      }
  
  
  
      return answer;
  
      //alt + shift + r
  
  
  
  }
  </code></pre>
  
  <p>Thank you.</p>