Question: Question 3: Clip list Implement clip_list(s, index), where s is an instance of the LinkNode class and index is a non- negative integer. The clip_list

 Question 3: Clip list Implement clip_list(s, index), where s is an

Question 3: Clip list Implement clip_list(s, index), where s is an instance of the LinkNode class and index is a non- negative integer. The clip_list function mutates s so that all elements that occur after the index are removed. The clip_list function should also return a linked list of all the removed elements. If the index exceeds the linked list, raise an IndexError exception. Your solution must use recursion; you may not use iteration. You may NOT assume that getting an element and length functions have been implemented. See the doctest for the expected behavior. Your solution should not require more than 8 lines, and you do not need to use all 8 lines. def clip list (s , index ) : >>sl -LinkNode (1 , LinkNode (2, LinkNode (3)) ) >>clip list s1 , 0) 2 -> 3 -> None >>>S1 1 -> None >>> s2 = LinkNode (1 , LinkNode (2 , LinkNode (3))) >>> clip 11st s2 , 2) == None # No elements after index 2 True >>S2 1- 2-> 3- None >>s3-LinkNode (1 , LinkNode (2, LinkNode (3)) ) >>> try : clip 1st ( s3 , 3) #no index 3 available . . . except (IndexError): ...p print("good job") good job # YOUR CODE GOES HERE #

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!