Question: In this exercise you will need to alter the implementations of the add(), remove() and search() functions so that they run recursively. I have begun

In this exercise you will need to alter the implementations of the add(), remove() and search() functions so that they run recursively. I have begun the process for you as follows:

In this exercise you will need to alter the implementations of the

Note that the assumptions we made for our implementation of the ordered list in lectures still hold true for the recursive implementation here. When you add an item you can assume that it is not already present in the list. When you remove an item you can assume that the item is present in the list.

Resources:

-------------------------

Classes:

add(), remove() and search() functions so that they run recursively. I have

Code to be completed:

begun the process for you as follows: Note that the assumptions we

Test Code:

made for our implementation of the ordered list in lectures still hold

def add (self,item) new nodeNode (item) currseli. h pre None self.add recursive (new node, curr,prev) head def search (self,item): curr-self. head return self.search recursive (item, curr) def remove (self,item): curr-self. head preNone self.remove recursive (item, curr,prev) You will need to implement the add_recursive (), search_recursive(), and remove_recursive) functions, which as their names suggest, must be recursive functions. No marks will be given for non-recursive implementations I have provided a file for you to use to test your ordered linked list implementation - A2Q1.py. You should get the same output regardless of whether you use the ordered linked list implementation discussed in class or the recursive implementation you complete for this assignment. An example of it running is shown below A2Q1py-CAUsers dazh001)Google Teaching CS1052017 Python 3.5.1 Shell File Edit Shell Debug Options Window Python 3.5.1 (v3.5.1:37a07 D64)1 on win32 Type "copyright", "credits Drive Work Window File Edit Format Run from OrderedList import OrderedList import random o list = orderedst() for i in range (10) RESTART: C: \Users\dazh001 rand-num = random. randrange (0,10) while o list.search (rand num): nments A2 A2Q1.py After insertion: 0 1 2 3 4 5 6 7 8 9 After deletion: rand num = random.randrange (0,10) o list.add (rand num) print("After insertion:" for item in o list print) for i in range (10) print (item,end-" ") rand-num = randon.randrange (0,10) while not (o 1ist.search (rand num)): rand-num randon.randrange (0,10) o list.remove (rand num) print("After deletion:") for item in o list: print (item,end-"") print)

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!