BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

Description:Return a given list in inorder
Python
Josemi
def inorden(monticulo,n=0):
    hijo1 = 2*n+1
    hijo2 = 2*n+2
    total=[]
    if hijo1 >= len(monticulo):
        return [monticulo[n]]
    elif hijo2 >= len(monticulo):
        return [monticulo[hijo1],monticulo[n]]
    else:
        total += inorden(hijo1,monticulo)
        total.append(monticulo[n])
        total += inorden(hijo2,monticulo)
        return total

Input example

monticulo = [3, 15, 68, 34, 39, 85, 85, 71, 47, 84]

Output example

total = [71, 34, 47, 15, 84, 39, 3, 85, 68, 85]
×Oh snap! Something wrong