title: coding with a singly linked list and bubble sort in java
body: <p>I have a problem with my code, I have made a singly linked list class in which you can add, remove, modify, merge etc... however, I am attempting a simple bubble sort and have come across problems in which the list is not correctly sorted. here are some things to note:</p>
  
  <ul>
  <li>it is a custom implementation of a linked list</li>
  <li>the nodes of the singly linked list contain 2 things: a CustomerFile object with all the data for a customer and a 'next' node pointer to the next item in the list</li>
  <li>the list is sorted in ascending order (A-Z) by the surname stored in the customer file of each node</li>
  <li>the add record function inserts the nodes at the correct position in the list so that the list does not need to be sorted initially - however if the surname is changed, as part of the program, the list needs to be sorted again</li>
  <li>I would rather not create a new list and re-use this insert record on that list to create a new list as this is memory intensive and my task is to be as efficient as possible</li>
  <li>the very structure of the linked list cannot be changed - it is decided and I am too far to change to something such as an array</li>
  <li>the list has a head node, it has next items but does not have a tail node. It has an appointed NULL next pointer to indicate the end pf the list</li>
  </ul>
  
  <h2>the code</h2>
  
  <pre><code>public static void sortList()
  {
      if (isEmpty() == true)
      {
          System.out.println("Cannot sort - the list is empty");
      }
      else if (getHead().getNext() == null)
      {
          System.out.println("List sorted");
      }
      else
      {
          Node current = getHead().getNext();
          CustomerFile tempDat;
          boolean swapDone = true;
          while (swapDone)
          {
              current = getHead().getNext();
              swapDone = false;
              while (current != null)
              {
                  if (current.getNext() != null &amp;&amp;
                      current.getData().getSurname().compareTo(
                          current.getNext().getData().getSurname()) &gt;0)
                  {
                      tempDat = current.getData();
                      current.setData(current.getNext().getData());
                      current.getNext().setData(tempDat);
                      swapDone = true;
                  }
                  current = current.getNext();
              }
          }
          if (getHead().getData().getSurname().compareTo(
              getHead().getNext().getData().getSurname()) &gt;0)
          {
              current = getHead().getNext();
              getHead().setNext(current.getNext());
              setHead(current);
          }
      }
  }
  </code></pre>
  
  <p>I would appreciate the feedback</p>