![]() |
VOOZH | about |
Given a pointer to the head node of a Linked List, the task is to create a copy of the linked list using recursion.
Examples::
Input: Head of following linked list
1->2->3->4->NULL
Output:
Original list: 1 -> 2 -> 3 -> 4 -> NULL
Duplicate list: 1 -> 2 -> 3 -> 4 -> NULLInput: Head of following linked list
1->2->3->4->5->NULL
Output:
Original list: 1->2->3->4->5->NULL,
Duplicate list: 1->2->3->4->5->NULL,
Approach: Follow the steps below to solve the problem:
Below is the implementation of the above approach:
Original list: 1 -> 2 -> 3 -> 4 -> 5 -> NULL Duplicate list: 1 -> 2 -> 3 -> 4 -> 5 -> NULL
Time Complexity: O(N)
Auxiliary Space: O(N)