I'm pretty new to java, and my doubly linked list addFront method and addRear method works fine, but only dequeue method doesn't works. In the main method, I making a test to remove front element using dequeueFront ()
method, when I remove front element it works, but If I continued removing front element,
Exception in thread "main" java.lang.NullPointerException
at DoublyLinkedDeque.dequeueFront(DoublyLinkedDeque.java:97)
comes out,
Line97 is the frontNode.previous=null
I just wondering how to remove front element form the double linked list properly.
public E dequeueFront() throws NoSuchElementException
{
if(frontNode!=null)
{
E frontElement=frontNode.element;
frontNode=frontNode.next;
frontNode.previous=null;
frontNode.next=null;
numElement--;
if(numElement==0)
rearNode=null;
return frontElement;
}
else
throw new NoSuchElementException();
}