a) In an unordered list, new items are added to the head. What is the content of the list after running the code below?

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

a) In an unordered list, new items are added to the head. What is the content of the list after running the code below?

Post by answerhappygod »

a) In an unordered list, new items are added to the head. What
is the content of the list after running the code below? The items
should be listed in the order counting from the head.
my_list = UnorderedList()
for num in [17, 7, 23, 45, 4, 3]:
my_list.add(num)
my_list.remove(3)
my_list.add(32)
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