Skip to content

Commit a76ab9d

Browse files
authored
Update Single-linked-list-operations.py
1 parent c622043 commit a76ab9d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Data Structures/Linked Lists/Singly Linked List/Single-linked-list-operations.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,26 @@ def insert_values(self, data_list):
9191

9292
# removing element at linkedlist with Value
9393
def removeval(self, value):
94-
if value == self.head.data:
95-
self.head = self.head.next
96-
return
94+
count = 0
9795
temp = self.head
9896
while temp:
99-
if value == temp.next.data:
100-
temp.next = temp.next.next
101-
break
102-
97+
if value != temp.data:
98+
count += 1
10399
temp = temp.next
100+
if count == self.length():
101+
print("Value is not present")
102+
103+
else:
104+
if value == self.head.data:
105+
self.head = self.head.next
106+
return
107+
temp = self.head
108+
while temp:
109+
if value == temp.next.data:
110+
temp.next = temp.next.next
111+
break
112+
113+
temp = temp.next
104114

105115

106116
if __name__ == '__main__':

0 commit comments

Comments
 (0)