The below code snippet is for deleting a node in linked list. My class contains two members namely data and next a pointer to hold other objects of that class type. When, I run my program, I don't get any error. If I try to delete the first item in the linked list, it enters the First for loop and displays the message "The data is found". But if I print my list, I am seeing the element in the list. I think this is because of assigning objects back, but I am not able to find where I have done that mistake. Any help is greatly appreciated.
def deleteNode(self, a_data):
flag = 0
if (self.data == a_data):
print("The data is found")
self = self.next
flag = 1
else:
while(self.next != None):
if (self.next.data == a_data):
self.next = self.next.next
flag = 1
break
else:
self = self.next
if(flag):
print("Data Deleted")
else:
print("Data not available")
Thanks