Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esame - #3 - 17 Gen 2024 #57

Open
rimaout opened this issue May 3, 2024 · 1 comment
Open

Esame - #3 - 17 Gen 2024 #57

rimaout opened this issue May 3, 2024 · 1 comment

Comments

@rimaout
Copy link
Member

rimaout commented May 3, 2024

image
Soluzione Prof image image
@rimaout
Copy link
Member Author

rimaout commented May 28, 2024

Codice:

def es(p):
    
    if p == None:   # controlo se radice dell'albero è sanza figli
        return 0    # questo contollo serve solo per la prima chiamata

    if p.left == None and p.right ==None:   # nodo senza filgi
        return 0

    if p.letf != None and p.right == None:  # nodo con solo figlio sinistro
        return es(p.left)

    # nodo con due figli (controllo se è valido)
    if (p.left.key < p.key < p.right.key) or (p.left.key > p.key > p.right.key):
        return 1 + es(p.left) + es(p.right)

    # nodo con due figli (ma non valido)
    return es(p.left) + es(p.right)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant