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
This is wrong. You can insert nodes in the middle of a singly linked list just fine. The only difference is that a doubly linked list is easier to navigate, since you can walk it forward and backward from any given node.
That depends entirely on what you are using the list for. Linked lists are not really a good general-purpose data structure due to their poor random access performance. Because of that, they are usually only used for algorithms that iterate over the list anyway and insert or remove nodes while they do it.
You’re approaching this from the wrong way, trying to write an application around a certain data structure. Normally you start out with the application’s end-user requirements and then decide which data structure is best used to satisfy those requirements. A User should never have to understand low-level internals of a program like linked lists.