This is a continuation of the previous message. Now I will look at how to insert the first node into an empty double-linked list. This seems to be hard to do first ... I would be grateful for a hint about what is missing in my addFirst method.
... public DLL() { first = null ; last = null ; } ... DLL myList = new DLL() ; DLLNode A = new DLLNode("Hello", null, null) ; ... myList.addFirst(A) ; ... public void addFirst(DLLNode v) { v.pred = first ; v.succ = last ; }
[EDIT]
The solution proposed by typo.pl:
public void addFirst(DLLNode v) { v.pred = first ; v.succ = last ; first = v ; last = v ; }
java linked-list
raoulbia
source share