Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (55.6k points)

Can anyone tell me how to reverse a singly linked list python?

1 Answer

0 votes
by (119k points)

Here is the recursive algorithm to reverse a singly linked list python:

def reverse(self,node):

       if node.getNextNode() == None:

           self.head = node

           return

       self.reverse(node.getNextNode())

       temp = node.getNextNode()

       temp.setNextNode(node)

       node.setNextNode(None)

I recommend enrolling in this Python Certification Course by Intelllipaat to learn Python.

Also, you can watch this video on the linked list in Python:

Related questions

0 votes
1 answer
asked Jul 11, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.6k points)

Browse Categories

...