title: Polynomial Representation in Java
body: <p>I want to represent a polynomial with the help of linked list. Here goes my code</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class Multiply_Poly
  {
      polynode head;
      Multiply_Poly()
      {
          head=null;
      }
  
      public void construct_poly(polynode head,float coeff,int exp)
      {
          if(head==null)
          {
              polynode newnode = new polynode(coeff,exp);
              head=newnode;
              return;
          }
          else
          {
              polynode newnode = new polynode(coeff,exp);
              polynode temp = head;
              while(temp.next!=null)
                  temp=temp.next;
  
              temp.next=newnode;
              temp=newnode;
          }
      }
  
      public void show_poly(polynode head)
      {
          if(head==null)
              return;
  
          else
          {
              while(head.next!=null)
              {
                  System.out.print("(" + head.coeff + ")" + "x^" + "(" + head.exp + ")" + "+");
                  head=head.next;
              }
  
              System.out.print("(" + head.coeff + ")" + "x^" + "(" + head.exp + ")");
          }
      }
  
      public static void main(String [] args)
      {
          Multiply_Poly m = new Multiply_Poly();
          m.construct_poly(m.head,12,5);
          m.construct_poly(m.head,9,4);
          m.construct_poly(m.head,26,3);
          m.construct_poly(m.head,18,2);
          m.construct_poly(m.head,10,1);
          m.construct_poly(m.head,5,0);
  
          m.show_poly(m.head);
      }
  }
  
  class polynode
  {
      float coeff;
      int exp;
      polynode next;
  
      polynode(float coeff,int exp)
      {
          this.coeff=coeff;
          this.exp=exp;
          next=null;
      }
  }
  </code></pre>
  
  <p>I think my construct_poly function is not working. That's why show_poly function returns null. Is my else part in construct_poly is not written correctly ? What is my mistake ?     </p>