title: polynomial addition using linked list in java
body: <p>Here's my implementation of a addition of two polynomials using a linked List.<br>
  For example if I want to add<br>
  3x^2+5^x+3 and 4x^3+5x+2  </p>
  
  <p>first I check if there are similar exponents in the two polynomials and if so I add their coefficients and I append the exponents to a string.<br>
  After adding similar exponents then using the string I add the remaining parts in both polynomials to the final result.  </p>
  
  <pre><code> public class Node2{
          int coef;
          int exp;
          Node2 next;
          Node2(int c,int e,Node2 n){
              coef=c;
              exp=e;
              next=n;
          }
          Node2(int c,int e){
              coef=c;
              exp=e;
  
          }
  
  
  }
  
  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 add(LinkedPoly list1,LinkedPoly list2){
      LinkedPoly addList=new LinkedPoly();
  
      Node2 temp1=list1.head;
              Node2 temp3=temp1;
      Node2 temp2=list2.head;
              Node2 temp4=temp2;
      while(temp1.next!=null){
          while(temp2.next!=null){
              if(temp1.exp==temp2.exp){
  
              addList.createList((temp1.coef+temp2.coef),temp1.exp);
              exponent+=temp1.exp;
  
              }
              temp2=temp2.next;
          }
          temp1=temp1.next;
          temp2=temp4;
      }
      String[] array=exponent.split("");
      for(int i=1;i&lt;array.length;i++){
  
          while(temp3.next!=null){
              if(temp3.exp!=Integer.parseInt(array[i])){
                  addList.createList(temp3.coef,temp3.exp);
              }
              temp3=temp3.next;
          }
          while(temp4.next!=null){
              if(temp4.exp!=Integer.parseInt(array[i])){
                  addList.createList(temp4.coef,temp4.exp);
              }
              temp4=temp4.next;
          }
      }
  
      return addList;
  }
  
  
  public static void main (String args[]){
      LinkedPoly l1=new LinkedPoly();
      l1.createList(3,2);
      l1.createList(5,1);
      l1.createList(3,0);
      LinkedPoly l2=new LinkedPoly();
      l2.createList(4,3);
      l2.createList(5,1);
      l2.createList(2,0);
  
      LinkedPoly l3=add(l1,l2);
      System.out.println(l3.head.next.next.coef);
  }
  </code></pre>
  
  <p>}  </p>
  
  <p>According to my example the exponent string include 1 and 0 ,but it only sums the coefficient of 1.Also the rest of the addition is also wrong.  </p>
  
  <p>I can't see where I am mistaking.Also how can I print out the final addList so that I can check if this implementation works fine</p>