How to Reverse a Linked List?
Its all here
Given a pointer to the head node of a linked list, the task is to reverse the linked list. The links between the nodes need to be changed in order to reverse the list.
Check out example
Divide the linked list in two parts, the first node and the rest, and call the recursion for the second part while maintaining the connection between them.
Check out its implementation
O(N), where N is the size of linked list.
Here, we'll use 3 variables i.e, prevNode, head, and nextNode.
- prevNode to NULL
- nextNode can stay empty.
Next steps to follow
O(N), where N is array size
How to implement these approaches in different programming languages?
Find out here