Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions python/add_and_subtract_nodes_in_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,7 @@ def subtract(self, value):
while current:
current.data -= value
current = current.next

#remove_nod
def remove_node(self,value):
"""Remove first occurence of a node
with the given value"""
current = self.head

#If list is empty
if not current:
print("List is empty.")
return

#If head node itself holds the value
if current.data == value:
self.head = current.next

#If not found
if not current:
print(f"Value{value}not foundin list.")
return

#unlink the code
prev.next = current.next

#sum_node
def sum_nodes(self):
"""Return the sum of all node vlaues"""
total = 0
current = self.head
while current:
total +=current.data
current = current.next
return total

# Print the linked list
def print_list(self):
current = self.head
Expand All @@ -81,10 +48,3 @@ def print_list(self):
ll.subtract(5)
print("After subtracting 5 from each node:")
ll.print_list()

print("/nRemoving node with value 10.")
11.remove_node(10)
11.print_list()

print("\nSum of nodes:",11.sum_nodes())