Question: Use the outline below as a starting from __future__ import annotations from typing import Any, Optional class Node: def __init__(self, value: Any, nxt: LinkedList): self.value

 Use the outline below as a starting from __future__ import annotations

Use the outline below as a starting

from __future__ import annotations

from typing import Any, Optional

class Node: def __init__(self, value: Any, nxt: LinkedList): self.value = value self.next = nxt

LinkedList = Optional[Node]

def empty_list() -> LinkedList: ...

def add(lst: LinkedList, index: int, value: Any) -> LinkedList: ...

def length(lst: LinkedList) -> int: ...

def get(lst: LinkedList, index: int) -> Any: ...

def setitem(lst: LinkedList, index: int, value: Any) -> LinkedList: ...

def remove(lst: LinkedList, index: int) -> tuple[Any, LinkedList]: ...

- empty_list This function takes no arguments and returns an empty list. - add This function takes a list, an integer index, and another value (of any type) as arguments and places the value at index position in the list (zero-based indexing; any element at the given index before this operation will now immediately follow the new element). If the index is invalid (i.e., less than 0 or greater than the current length), then this operation should raise an IndexError . (Note that an index equal to the length is allowed and results in the new value being added to the end of the list.) This function must return the resulting list. - length This function takes a list as an argument and returns the number of elements currently in the list. - get This function takes a list and an integer index as arguments and returns the value at the index position in the list (zero-based indexing). If the index is invalid (i.e., it falls outside the bounds of the list), then this operation should raise an IndexError. - setitem This function takes a list, an integer index, and another value (of any type) as arguments and replaces the element at index position in the list with the given value. If the index is invalid, then this operation should raise an IndexError. This function must return the resulting list. - remove This function takes a list and an integer index as arguments and removes the element at the index position from the list. If the index is invalid (i.e., it falls outside the bounds of the list), then this operation should raise an IndexError. This function must return a 2-tuple of, in this order, the element previously at the specified index (i.e., the removed element) and the resulting list. 2 Linked List In a file named linked_list.py, provide a data definition for a LinkedList, whose Node class's value field can be any value. An empty list should be represented by the Python value None. Be sure to call your node class Node, so that my tests can create objects correctly. Implement the functions listed above. None of the functions should modify the list that you're given. All of the functions should return a new list. Additionally, implement the eqfunction in your Node class. This will help with testing

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!