Question: write a function: def firstEven (self, d) that returns the index of the first element of the linked list that is even. If there

write a function: def firstEven (self, d) that returns the index of the first element of the linked list that

write a function: def firstEven (self, d) that returns the index of the first element of the linked list that is even. If there are no even elements in the list, the function should return -1. For example, if 1s is the list [4,5,6,7,8] then ls.firstEven() should return 0. Write a function: def decide (self, f) that takes as input a function f that returns booleans. Your function should return a pair (1sT, 1sF) of two new linked lists, where 1sT contains all the elements of the linked list (i.e. of self) for which f returns True when applied on them, and 1sF contains all remaining elements. The order of the elements in the two lists should be the same as in self. The list self should remain unchanged. For example, if isOdd is the function that returns True when applied to odd numbers, and False otherwise, and 1s is the list [4,5,2,5,4,7,6,7,8] then ls.decide (isOdd) should return the pair of linked lists ([5,5,7,7], [4,2,4,6,8]). For full marks, your solution should run in time linear in the length of the linked list. Ac Gc

Step by Step Solution

3.25 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve the problem in the image we can use the following Python functions Python def firstEvenself d Returns the index of the first even element in ... View full answer

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 Programming Questions!