Skip to content

Conversation

@amirsoroush
Copy link

In "Chapter04/delete_operation_doubly_linkedlist.py" in case where the item to be deleted is found at starting of the list, there is currently a bug:

    def delete(self, data):
        # Delete a node from the list. 
        current = self.head 
        node_deleted = False 
        if current is None:       #List is empty
            print("List is empty")
        elif current.data == data:   #Item to be deleted is found at starting of list
            self.head.prev = None 
            node_deleted = True 
            self.head = current.next

The self.head.prev = None line has no effect because it's already None. Therefore when self.head = current.next line is executed we'll have a head which has a prev!

To fix it all we have to do is move the self.head = current.next line to the top so that after the new head is assigned, we set its prev to None.

@Yashwanth-K
Copy link

yes you are right..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants