Question: JAVA method for removing a cursor from a doubly linked list. Please help me write a working method. This is my current method but it
JAVA method for removing a cursor from a doubly linked list. Please help me write a working method.
This is my current method but it does not work property. when I call .cursor.getPrev().getData() in the main method, the old cursor still appears, it has not been properly dislodged from the doubly linked list.
if(cursor == null || head == null){
throw new EndOfListException("cursor is null.");
}
else if(cursor.getPrev() == null){
head = cursor.getNext();
cursor.setNext(null);
cursor.setPrev(null);
cursor = head;
}
else if(cursor.getNext() == null){
tail = cursor.getPrev();
cursor.setPrev(null);
cursor.setNext(null);
cursor = tail;
}
else {
cursor.getPrev().setNext(cursor.getNext());
cursor.getNext().setPrev(cursor.getPrev());
cursor.setData(null);
cursor.setNext(null);
cursor.setPrev(null);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
