Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON:::::Write a LinkedList class that has recursive implementations of the add, display, and remove methods described in the lesson. It should also have recursive implementations

PYTHON:::::Write a LinkedList class that has recursive implementations of the add, display, and remove methods described in the lesson. It should also have recursive implementations of the contains, insert, and reverse methods described in the exercises. You may use default arguments and/or helper functions.

The file must be named: LinkedList.py

Need to have recursive functions for add, display, remove as well. Same with contains, insert, reverse. below are functions given but need to be translated to recursive. Need help. I'm stuck. No loops allowed in LinkedList as well.

class Node: def __init__(self, data): self.data = data self.next = None

class LinkedList: def __init__(self): self.head = None def add(self, val): if self.head is None: self.head = Node(val) else: current = self.head while current.next is not None: current = current.next current.next = Node(val) def display(self): current = self.head while current is not None: print(current.data, end="") current = current.next print() def remove(self, val): if self.head is None: return

if self.head.data == val: 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: previous.next = current.next def is_empty(self): return self.head is None

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions