donnemartin / interactive-coding-challenges

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Append method of linkedlist implementation has a bug

glang opened this issue · comments

https://github.com/donnemartin/interactive-coding-challenges/blob/master/linked_lists/linked_list/linked_list_solution.ipynb

When self.head == None, the node returned is not the node assigned to self.head. self.head should be assigned node.

I just found that the delete method also has a bug. When self.head.data == data, self.head is set to None and that deletes the whole linkedlist and not just the head... self.head should be set to self.head.next in that case.

Hi @glang good catch! Are you interested in submitting a pull request? Thanks!

Hi @glang!

I am trying to follow the problem. Where the self.head should be return an assigned node? Is in def append(self, data)?

Regards!

@donnemartin I see @eamanu has already fixed the delete method bug, as for the append method bug,

        if self.head is None:
            self.head = Node(data) #should be self.head = node
            return node