removes all the elements from a linked list python

Solutions on MaxInterview for removes all the elements from a linked list python by the best coders in the world

showing results for - "removes all the elements from a linked list python"
Irene
29 Mar 2017
1def deleteAllNodes(self):
2
3  #1 & 2. create a temp node, if the head is not  
4  #   null make temp as head and move head to head 
5  #   next, then delete the temp, continue the 
6  #   process till head becomes null
7  while (self.head != None):
8    temp = self.head
9    self.head = self.head.next
10    temp = None
11
12  print("All nodes are deleted successfully.")