Giorgos Myrianthous
1 min readDec 22, 2021

--

Hi Scott, I'm glad you liked the article!

So I don't think that it's required to override add_node_as_head method in DoublyLinkedList class.

When adding the new node as head in a Doubly Linked List, we would still check if there's actually no head node (if self.head is None). In this case, this will be the first node to be added and thus it will essentially be the tail as well as the head of the Doubly Linked List (head.next and head.prev will be None).

Now if there's at least one node in the Linked List already, then we simply need to set it as the head where the next value will now be equal to the current head and prev will still be None (as this is the head of the Linked List).

So I think the existing implementation in LinkedList class covers the functionality required in Doubly Linked Lists.

Let me know if this is clear.

--

--

Giorgos Myrianthous
Giorgos Myrianthous

Written by Giorgos Myrianthous

I strive to build data-intensive systems that are not only functional, but also scalable, cost effective and maintainable over the long term.

Responses (1)