1

I know how to add nodes before and after the head and tail, but I dont know how to add a node to an empty doubly linked list. How would I go about doing this? Thank you.

asked Mar 29, 2013 at 12:45
1
  • 2
    That depends on the implementation of a doubly-linked list that you're using -- Python doesn't come with one. But the sensible thing would be to add it exactly the way you would add a node to a non-empty list, except that now it doesn't matter whether you add it to the head or the tail. Commented Mar 29, 2013 at 12:47

1 Answer 1

1

When inserting into an empty list, make both head and tail refer to the new node. Also, make sure that the node's next and previous references are consistent with what the rest of the code is expecting.

answered Mar 29, 2013 at 12:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.