'Why is my doubly linked list not adding elements to the list

I am supposed to write a code that pushed nodes to the doubly linked stack, except I have to have the first added element (top) at the end of the stack, meaning the last added element should be the first one in the doubly linked list.

Here's my code for the push method

public void push(T dataItem) {
    
    DoubleLinkedNode<T> newNode = new DoubleLinkedNode<T>(dataItem);
    
    if(top == null) {
        
        top = newNode;
        
    }
    
    else {
         
        DoubleLinkedNode<T> currentNode = top;
        
        while (currentNode.getPrevious() != null){
            
            currentNode = currentNode.getPrevious();
            
        }
        
        newNode.setNext(currentNode);
        currentNode.setPrevious(newNode);
        
    }
    
    numItems++;
    
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source