public void removeSmallest() { Node smallest = head; Node temp = head; Node prev = null; while(temp != null) { if(temp.next != null && temp.next.data < smallest.data){ smallest = temp.next; prev = temp; } temp = temp.next; } if(smallest != head) { //First element is not min prev.next = smallest.next; } else { head = head.next; //If first element is smallest, update the head } }