Question: Note that this is considered a private class, one which is only meant to be used in this module by the LinkedList class, but


Note that this is considered a "private class", one which is only meant to be used in this module by the LinkedList class, but not by client code. ====Attributes === item: The data stored in this node. next: The next node in the list, or None if there are no more nodes. *** item: Any next: Optional[_Node] def _init__(self, item: Any) -> None: """Initialize a new node storing , with no next node. www self.item = item self.next = None # Initially pointing to nothing class Linked List: """A linked list implementation of the List ADT. www Private Attributes === # _first: # The first node in the linked list, or None if the list is empty. first: Optional[_Node] def init (self, items: list) -> None: ***Initialize a new linked list containing the given items. The first node in the linked list contains the first item in . www if len(items) == 0: # No items, and an empty list! self._first = None else: self._first = _Node (items[0]) curr = self._first for item in items [1:]: curr.next = _Node (item) curr = curr.next def _str_ (self) -> str: """Return a string representation of this list in the form [item1 -> item2 -> ... > item-n]'. >>> str(LinkedList([1, 2, 3])) [12-> 3]' >>> str(LinkedList([])) '[]' items = [] curr = self._first while curr is not None: items.append(str (curr.item)) curr = curr.next return [ + ->.join(items) + ']' def change_last (self, v: int) -> Optional[int]: www Change the last node in this linked list to contain v, and return the value that used to be there. If there are no nodes, change nothing and return None. >>> Linky = LinkedList([5, 15, 10, 201) >>> Linky.change_last (99) 28 >>>print(linky) [515 > 10 -> 99] >>> linky = LinkedList([5]) >>> Linky.change_last (99) 5 >>> print (linky) [99] >>> Linky = Linked List([]) >>> Linky.change_last (99) is None True >>> print (linky) [] www if False: # TODO: Replace False with appropriate if-condition pass # TODO: Replace pass with one line of code else: curr = self._first while False: # TODO: Replace False with appropriate while-condition curr = curr.next pass # TODO: Replace pass with one line of code curr.item = v return answer
Step by Step Solution
3.37 Rating (147 Votes )
There are 3 Steps involved in it
fromfuture import annotations from typing import An... View full answer
Get step-by-step solutions from verified subject matter experts
