Adding to a linked list in the right alphabetical position [Java] : My assignment is to modify the below code so it positions new elements alphabetically in the linkedlist. It currently adds the element to the end of the list.

    public void add(String element)
    {
    Node newNode = new Node(element);
    if (first == null)
      first = newNode;
    else
    {
      // Find the predecessor of the element to add
      Node current = first;
      Node prev = null;
      while (current != null) {
        prev = current;
        current = current.next;
      }
      // New last element 
      if (current == null) 
        prev.next = newNode;
      else if (prev == null)
      {
            newNode.next = first;
            first = newNode;
      }
    }
   
    }