python-data-structures icon indicating copy to clipboard operation
python-data-structures copied to clipboard

Missing last = n in LinkedList remove method

Open rodrigo-albuquerque opened this issue 6 years ago • 0 comments

def remove(self, value):
    n = self.head
    last = None
    while n != None:
        if n.value == value:
            if last == None:
                self.head = self.head.next
            else:
                last.next = n.next
            return True
        last = n  **<-- This is missing**
        n = n.next
    return False

rodrigo-albuquerque avatar Sep 03 '18 14:09 rodrigo-albuquerque