How to reverse a singly linked list?



How to reverse a singly linked list?..

Answer / Vikram Kapoor

To reverse a singly linked list, you can use recursion or iterative methods. Here's a simple recursive implementation in Python:

```python
def reverseList(head):
def _reverse(prev, current):
if not current:
return prev
nextNode = current.next
current.next = prev
return _reverse(current, nextNode)

return _reverse(None, head)
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

how to display Singly Linked List from First to Last?

1 Answers  


Write a Program for Reverse a linked list.

1 Answers  


Why is sorting and classifying important?

1 Answers  


Is bucket sort stable?

1 Answers  


Which is the parent class of hashmap class?

1 Answers  


What is the height of binary tree?

1 Answers  


Which list does not allow duplicates?

1 Answers  


Is quicksort a stable sorting algorithm?

1 Answers  


How do arrays work?

1 Answers  


List the applications of stacks?

1 Answers  


Explain the Linked List

1 Answers   Tech Mahindra,


What is faster array or arraylist?

1 Answers  


Categories