title: Polynomial addition using Linked List
body: <p>This is a code for polynomial addition using linked lists.  </p>
  
  <pre><code>public class LinkedPolynomial{
      private Node first=new Node(0,0);
      private Node last=first;
      private static class Node{
          int coef;
          int exp;
          Node next;
          Node(int coef,int exp){
              this.coef=coef;
              this.exp=exp;
          }
      }
      private LinkedPolynomial(){}
      public LinkedPolynomial(int coef,int exp){
          last.next=new Node(coef,exp);
          last=last.next;
      }
      //return c=a+b
      public LinkedPolynomial plus(LinkedPolynomial b){
          LinkedPolynomial a = this;
          LinkedPolynomial c = new LinkedPolynomial();
          Node x=a.first.next;
          Node y=b.first.next;
          while(x!=null || y!=null){
              Node t=null;
              if(x==null){
                  t=new Node(y.coef,y.exp);
                  y=y.next;
              }
              else if(y==null){
                  t=new Node(x.coef,x.exp);
                  x=x.next;
              }
              else if(x.exp&gt;y.exp){
                  t=new Node(x.coef,x.exp);
                  x=x.next;
              }
              else if {
                  t=new Node(y.coef,y.exp);
                  y=y.next;
              }
              else{
                  int coef=x.coef+y.coef;
                  int exp=x.exp;
                  x=x.next;
                  y=y.next;
                  if(coef==0)
                      continue;
                  t=new Node(coef,exp);
              }
              c.last.next=t;
              c.last=c.last.next;
  
          }
          return c;
  
      }
      public static void main (String args[]){
          LinkedPolynomial zero=new LinkedPolynomial(0,0);
          LinkedPolynomial p1=new LinkedPolynomial(4,3);
      }
  }
  </code></pre>
  
  <p>In the method <code>plus()</code> can someone please explain to me what is done with   </p>
  
  <pre><code>LinkedPolynomial a = this;
  LinkedPolynomial c = new LinkedPolynomial();
  Node x=a.first.next;
  Node y=b.first.next;  
  </code></pre>
  
  <p>What is  <code>a.first.next;</code>  </p>
  
  <p>What is <code>LinkedPolynomial</code>. Is it a node? Does every <code>LinkedPolynomial</code> has a first and last?  </p>
  
  <p>Can someone please explain these to me.</p>