title: Add nodes in linked list
body: <p>Trying to implement <code>single-linked-list</code> in below program, i am really not able to undertsand how to add a node in an Linked list (for start, m trying it on <em>empty linked list</em>).</p>
  
  <p>To put it plain simple,i tried to <code>setData</code> and <code>setNext</code> but <code>getSizeofList()</code> return <code>0</code> everytime....its really looking like a rocket science to me now!!</p>
  
  <p><strong>Question :</strong> Can some-one tell me how to implement it....or rather, add a node to existing linked list....</p>
  
  <p><strong>What i have tried so far and why they dint worked out:</strong> i referenced multiple programs but they were too complex for me to understand(<em>rocket science</em>), so wrote below program from what i understood from algorithms....but even in algo's, they just show methods on how to implement and this is where i failed, as, i dont understand,what <code>data-type</code> and <code>value</code> is to be passed for adding a node...</p>
  
  <p><br ><em>please not that m not a java guy, so please go easy, this question comes in as an attempt to learn</em></p>
  
  <pre><code>package Data_S;
  
  public class Linked_List {
  
      private int data;
      private Linked_List next_ptr;
      private Linked_List headNode = null;
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          Linked_List ll = new Linked_List();
          //ll.setnext(25);
          ll.insert_node(24);
          ll.traverse();
          ll.getSizeofList();
      }
  
  
      //size of list
      public void getSizeofList()
      {
          int l = 0;
          Linked_List curr = headNode;
          while(curr != null)
          {
              l++;
              curr = curr.getnext();
          }
          System.out.print("Size of list is = "+l);
      }
  
      //insert node
      public void insert_node(/*Linked_List node, */int data)
      {
          if(headNode == null)
          {
              System.out.println("in insert"); // checking
              this.setnext(headNode);
              this.setData(data);
              System.out.print("value = "+this.getData());
          }
      }
  
     //set data for this node
      public void setData(int data)
      {
          this.data = data;
      }
  
      //return the data
      public int getData()
      {
          return this.data;
      }
  
      //set next pointer
      public void setnext(Linked_List next_ptr)
      {
          this.next_ptr = next_ptr;
      }
  
      //get next pointer
      public Linked_List getnext()
      {
          return this.next_ptr;
      }
  
  
  }
  </code></pre>