title: Insertion into Doubly linked list
body: <p>I have a problem with addition of elements in Liked List</p>
  
  <pre><code>public class LinkedList {
      public Node first;
      public Node last;
  
      public LinkedList() {
          first = null;
          last = null;
      }
  
      public void addFirst(Student student) {
          Node f = first;
          Node newNode = new Node(student);
          first = newNode;
          if (f == null) last = newNode;
          else f.previous = newNode;
      }
  
      public void addLast(Student student) {
          Node l = last;
          Node newNode = new Node(student);
          last = newNode;
          if (l == null) first = newNode;
          else {
              l.next = newNode;
          }
      }
  
  
      public void display() {
          Node current = first;
          while (current != null) {
              //print...
              current = current.next;
          }
      }
  </code></pre>
  
  <p>My problem is when I run:</p>
  
  <pre><code>list.addLast(1);
  list.addFirst(2);
  list.display();
  </code></pre>
  
  <p>It displays just "2" 'display' method just can't see last added element.<br>
  But if I run:</p>
  
  <pre><code>list.addFirst(2);
  list.addLast(1);
  </code></pre>
  
  <p>It will display both.
  What is wrong with it?
  Thanks.</p>