title: multiplying polynomials using linked list in java
body: <p>This is my code for multiplying two polynomials using liked list.It works fine but the problem is if I multiply (3x^2+5x+3)*(4x^3+5^x+2)  </p>
  
  <p>I get the result as 12x^5+15x^2+6x^2+20x^4+25x^2+10x+12x^3+15x
  +6.  </p>
  
  <p>But how can I make it so that it outputs the terms with similar exponents are added togther like 12x^5+43x^2+..  </p>
  
  <pre><code>public class LinkedPoly{
      static String exponent="";
      Node2 head;
      Node2 current;
  
      LinkedPoly(){
          head=null;
  
      }
      public void createList(int c,int e){
          head=new Node2(c,e,head);
      }
      public static LinkedPoly multiply(LinkedPoly list1,LinkedPoly list2){
          Node2 temp1=list1.head;
          Node2 temp2=list2.head;
          Node2 temp3=temp2;
          LinkedPoly multiplyList=new LinkedPoly();
  
          while(temp1!=null){
              while(temp2!=null){
                  multiplyList.createList((temp1.coef*temp2.coef),(temp1.exp+temp2.exp)); 
                  temp2=temp2.next;
              }
              temp2=temp3;
              temp1=temp1.next;
          }
  
          return multiplyList;
      }
  </code></pre>