Doubly Linked Lists Implementation
- by user552127
Hi All,
I have looked at most threads here about Doubly linked lists but still unclear about the following.
I am practicing the Goodrich and Tamassia book in Java. About doubly linked lists, please correct me if I am wrong, it is different from a singly linked list in that a node could be inserted anywhere, not just after the head or after the tail using both the next and prev nodes available, while in singly linked lists, this insertion anywhere in the list is not possible ?
If one wants to insert a node in a doubly linked list, then the default argument should be either the node after the to-be inserted node or node before the to-be inserted node ? But if this is so, then I don't understand how to pass the node before or after.
Should we be displaying all nodes that were inserted till now and ask the user to select the node before or after which some new node is to be inserted ? My doubt is how to pass this default node. Because I assume that will require the next and prev nodes of these nodes as well.
For e.g, Head<-A<-B<-C<-D<-E<-tail
If Z is the new node to be inserted after say D, then how should node D be passed ? I am confused with this though it seems pretty simple to most.
But pl do explain.
Thanks,
Sanjay