![]() |
VOOZH | about |
Given a doubly linked list, The task is to find the size of the given doubly linked list.
Example:
Input : 1<->2<->3<->4
output : 4
Explanation: The size is 4 as there are 4 nodes in the doubly linked list.Input : 1<->2
output : 2
The idea is to traverse the doubly linked list starting from the head node. Increment the size variable until we reach the end.
4
The idea is to use a recursive function that takes a node and check the next pointer of the current node if the next pointer is NULL then return 0 else if the next pointer is not NULL then return 1 + the value returned by the recursive function for the next node.
Size of the doubly linked list: 4