Check out example codes for "Describe a recursive algorithm that counts the number of nodes in a singly linked list.". It will help you in understanding the concepts better.

Code Example 1

# A complete working Python program to find length of a 
# Linked List recursively 
# Node class 
class Node: 
    # Function to initialise the node object 
    def __init__(self, data): = data  # Assign data = None  # Initialize next as null 
# Linked List class contains a Node object 
class LinkedList: 
    # Function to initialize head 
    def __init__(self): 
        self.head = None
    # This function is in LinkedList class. It inserts 
    # a new node at the beginning of Linked List. 
    def push(self, new_data): 
        # 1 & 2: Allocate the Node & 
        #        Put in the data 
        new_node = Node(new_data) 
        # 3. Make next of new Node as head = self.head 
        # 4. Move the head to point to new Node 
        self.head = new_node 
    # This function counts number of nodes in Linked List 
    # recursively, given 'node' as starting node. 
    def getCountRec(self, node): 
        if (not node): # Base case 
            return 0
            return 1 + self.getCountRec( 
    # A wrapper over getCountRec() 
    def getCount(self): 
       return self.getCountRec(self.head) 
# Code execution starts here 
if __name__=='__main__': 
    llist = LinkedList() 
    print 'Count of nodes is :',llist.getCount()

Learn ReactJs, React Native from