My teacher started talking about recursion, and spent some exercises, only that I caught on one.
As I said in the statement below, I should create a function that returns the largest value contained in a list.
My problem is: I can not do this using recursion. My idea was to type a bubble sort and then only display the last element, however, the following error is occurring:
RecursionError: maximum recursion depth exceeded in comparison
I can not think of another way to do it.
Recursively implement a Max
function that returns the highest value stored in a V
vector, containing n
integers
global c
global c2
global temp
x = [5, 2, 8, 4, 6, 9, 0, 1]
c = 0
c2 = 1
temp = max(x)
def Max(x):
global c
global c2
if x[c] > x[c2]:
x[c], x[c2] = x[c2], x[c]
c += 1
c2 += 1
if x[len(x)-1] != temp:
Max(x)
return x
print(Max(x))