I tried the following code to reverse a linked list and is getting an infinite loop as an error. Can you pls tell me what's wrong in this approach.
def reverse(self):
temp = curr = self.head #curr refers to the next node
prev = None
while temp:
curr = temp.next #curr goes to the next node of temp
curr.next = temp #curr node points to its previous node temp
prev = temp #prev moves to the next node
temp = curr
#self.head.next = None
self.head = prev