From 54570828945d9efc01e356ff0c763107dfb7b101 Mon Sep 17 00:00:00 2001 From: Rohan Vijay Date: Tue, 28 Jul 2020 04:19:41 +0530 Subject: [PATCH] changes in deleteValue function head pointed was not changing. --- src/chapter03linkedlists/LinkedList.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/chapter03linkedlists/LinkedList.py b/src/chapter03linkedlists/LinkedList.py index 8eeb19d..318e2b6 100644 --- a/src/chapter03linkedlists/LinkedList.py +++ b/src/chapter03linkedlists/LinkedList.py @@ -135,10 +135,14 @@ def deleteLast(self): def deleteValue(self, data): currentnode = self.head previousnode = self.head - - while currentnode.next != None or currentnode.data != data: + while currentnode.next != None:# or currentnode.data != data: + if currentnode.data == data: - previousnode.next = currentnode.next + + if self.head.data==data: + self.head=previousnode.next = currentnode.next + else: + previousnode.next = currentnode.next self.length -= 1 return