For an assignment, I have to find the maximum element's index recursively. How can I do that?
I've tried the following function, but I keep getting wrong results:
def maxElement(A):
if len(A)==1:
return A[0]
else:
max=maxElement(A[1:])
if A[0]>max:
return A[0]
else:
return max
A=[9, 16, 100, 36, 4, 25, 1, 81, 49, 9, 64]
print(maxElement(A))
I should get 2, since it's the third element, but I keep getting 100.