b) search_loop is a function to search a singly linked list. Its expected results are illustrated below. Write a functio

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

b) search_loop is a function to search a singly linked list. Its expected results are illustrated below. Write a functio

Post by answerhappygod »

b) search_loop is a function to search a singly linked list. Its
expected results are illustrated below. Write a function that
implement the same effect in a recursive algorithm.
def search_loop(list_head, item):
cur = list_head
found = False
while cur != None and not found:
if cur.getData()
== item:
found
= True
else:
cur
= cur.getNext()
return found
my_list = UnorderedList()
for num in [5, 7, 3, 9, 1]:
my_list.add(num)
search_loop(my_list.head, 3) # returns True
search_loop(my_list.head, 2) # returns False
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply