title: Doubly-linked list insertion sort function: Why isn't my insertion sort function inserting the last two integer inputs into my linked list?
body: <p>My insertion sort function does not seem to be inserting my last two integer inputs: 15 and 8, into my doubly linked list.  My output leaves out 15 and 8.  What am I doing wrong in the insertion sort function?  I have provided my functions' code, input, and output.  Thank you.</p>
  
  <p><strong>Here is my insertion sort function:</strong></p>
  
  <pre><code>    public void insertionSort(int p)
     {
      Node n = new Node(p);
      Node curr = head;
  
      if(isEmpty())
      {
          head = n;
      }
  
      else
      {
          if(n.getProb() &lt;= curr.getProb())
          {
              n.setNext(curr);
              curr.setPrev(n);
              head = n;
          }
  
          else if(n.getProb() &gt; curr.getProb())
          {
              while(n.getProb() &gt; curr.getProb() &amp;&amp; curr.getNext() != null)
              {
                  curr = curr.getNext();
              }
  
              if(n.getProb() &lt; curr.getProb())
              {
                  n.setNext(curr);
                  n.setPrev(curr.getPrev());
                  curr.setPrev(n);
              }
  
              else if(n.getProb() &gt;= curr.getProb())
              {
                  n.setNext(curr.getNext());
                  n.setPrev(curr);
                  curr.setNext(n);
              }
          }
      }
      size++;
    }
  </code></pre>
  
  <p><strong>Here is my print function</strong></p>
  
  <pre><code>    public void printSortedList()
  {
      Node curr = head;
  
      while(curr != null)
      {
          System.out.println(curr.getProb());
          curr = curr.getNext();
      }
  }
  </code></pre>
  
  <p><strong>Here is how I input in my main function:</strong></p>
  
  <pre><code>public static void main(String [] args)
  {
      List list = new List();
  
      list.insertionSort(10);
      list.insertionSort(5);
      list.insertionSort(5);
      list.insertionSort(60);
      list.insertionSort(5);
      list.insertionSort(10);
      list.insertionSort(15);
      list.insertionSort(8);
  
      list.printSortedList();
  }
  </code></pre>
  
  <p><strong>Here is my output:</strong></p>
  
  <pre><code>5
  5
  5
  10
  10
  60
  </code></pre>