Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please implement add_back (below) SOLUTION MUST BE RECURSIVE! This method adds a new node at the end of the list (right before the back sentinel).

please implement add_back (below) SOLUTION MUST BE RECURSIVE! This method adds a new node at the end of the list (right before the back sentinel). Testing Example #1: lst = LinkedList() print(lst) lst.add_back('C') lst.add_back('B') lst.add_back('A') print(lst) Output: SLL[] SLL[C -> B -> A] class LinkedList: def __init__(self, start_list=None): """ Initializes a new linked list with front and back sentinels DO NOT CHANGE THIS METHOD IN ANY WAY """ self.head = SLNode(None) self.tail = SLNode(None) self.head.next = self.tail # populate SLL with initial values (if provided) # before using this feature, implement add_back() method if start_list is not None: for value in start_list: self.add_back(value) def __str__(self) -> str: """ Return content of singly linked list in human-readable form DO NOT CHANGE THIS METHOD IN ANY WAY """ out = 'SLL [' if self.head.next != self.tail: cur = self.head.next.next out = out + str(self.head.next.value) while cur != self.tail: out = out + ' -> ' + str(cur.value) cur = cur.next out = out + ']' return out def length(self) -> int: """ Return the length of the linked list DO NOT CHANGE THIS METHOD IN ANY WAY """ length = 0 cur = self.head while cur.next != self.tail: cur = cur.next length += 1 return length def is_empty(self) -> bool: """ Return True is list is empty, False otherwise DO NOT CHANGE THIS METHOD IN ANY WAY """ return self.head.next == self.tail # ------------------------------------------------------------------ # 
 def add_back(self, value: object) -> None: """ Add value to back or list

SOLUTION MUST BE RECURSIVE!

"""

python code here

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

=+2 How does the preparation and support for each type of IE vary?

Answered: 1 week ago

Question

=+What is the extent of the use of each type of IE?

Answered: 1 week ago