Question: *python 3* I need help rewriting these iterative functions in this linked list to be implemented as recursive functions, the docstrings bolded show the ones

*python 3*

I need help rewriting these iterative functions in this linked list to be implemented as recursive functions, the docstrings bolded show the ones I need help with. Helper functions and default parameters are ok.

class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def add(self, val): """ This needs to be done recursively """ if self.head is None: # If the list is empty self.head = Node(val) else: current = self.head while current.next is not None: current = current.next current.next = Node(val) def display(self): """ This needs to be done recursively """ current = self.head while current is not None: print(current.data, end=" ") current = current.next print() def remove(self, val): """ needs to be done recursively """ if self.head is None: # If the list is empty return if self.head.data == val: # If the node to remove is the head self.head = self.head.next else: current = self.head while current is not None and current.data != val: previous = current current = current.next if current is not None: # If we found the value in the list previous.next = current.next

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!