Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions