Define a recursive function named trim; it takes as its arguments a linked list (the head node of it) and a non-negative integer representing the index of an element in the list. The function mutates...





Define a recursive function named trim; it takes as its arguments a linked list (the head node of it) and a non-negative integer representing the index of an element in the list. The function mutates the linked list such that all elements that occur after the index is removed. Additionally, the function returns a linked list of all the elements that were moved. If the index value exceeds the length of the linked list, it should raise an IndexError. For example, if we defined a list as l1 = LN(1, LN(2, LN 3))) , calling the function would return the linked list LN(2, LN(3)), and the mutated l1 would become LN(1). You must use recursion.


def trim(l: LN, index: int) -> LN:






Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here