I have a code which add a node at the end of a LinkedList but I don't understand how it works: when the code ends else statement the top node has the previous elements and add the pointer elements at the final of the list.
I don't know when the pointer elements are added at top node. Why does this happen and how does it works?
//Link element as latest of the List
public void addAtTheEnd(T element) {
Node<T> aux = new Node<>(element);
if(this.isEmpty()) {
top = aux;
} else {
Node<T> pointer = top;
while (pointer.getNext() != null) {
pointer = pointer.getNext();
}
pointer.setNext(aux);
}
size++;
}

