Answers for "Removes all the elements from a linked list python"

0

Removes all the elements from a linked list python

def deleteAllNodes(self):

  #1 & 2. create a temp node, if the head is not  
  #   null make temp as head and move head to head 
  #   next, then delete the temp, continue the 
  #   process till head becomes null
  while (self.head != None):
    temp = self.head
    self.head = self.head.next
    temp = None

  print("All nodes are deleted successfully.")
Posted by: Guest on July-17-2021

Code answers related to "Removes all the elements from a linked list python"

Python Answers by Framework

Browse Popular Code Answers by Language