I have below code. I am trying to delete the last node. But the node is not getting deleted. The temp
is still holding the all the data
. I did not understand that, in Python the assignment means deep copy or shallow copy
?
class ll:
def __init__(self, data):
self.data = data
self.next = None
def adddata(self, data):
if not self.next:
self.next = ll(data)
return
self.next.adddata(data)
def display(root):
if root == None:
return
print root.data
display(root.next)
def delete_last(root):
temp = root
myfrontptr = root.next
while myfrontptr.next != None:
root = root.next
myfrontptr = myfrontptr.next
if root.next != None and myfrontptr.next == None:
del myfrontptr
return temp
l = ll(1)
l.adddata(5)
l.adddata(3)
l.adddata(2)
l.adddata(0)
l.adddata(4)
l = delete_last(l)
display(l)