If add_node is supposed to add num_m nodes to the list then you've made the mistake of using a loop and recursion at the same time. You want to just use the recursion. Your base case would be num_m <= 0 in which case you just return. The recursive call would pass in num_m - 1.