Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Albero:
- def __init__(self, v): #costruttore
- self.val = v
- self.sx = None
- self.dx = None
- def cerca(a,valore):
- if a is None:
- return False
- if a.val == valore:
- return True
- if a.sx is None and a.dx is None:
- return False
- cerca_sx = False
- cerca_dx = False
- if a.sx is not None:
- cerca_sx = cerca(a.sx,valore)
- if a.dx is not None:
- cerca_dx = cerca(a.dx,valore)
- if cerca_sx is True or cerca_dx is True:
- return True
- else:
- return False
- def prova(a):
- if a == 1:
- return "ciao"
- if a == 10:
- return "ciaociaociao"
- return "niente"
- ###main
- a = Albero(1)
- b = Albero(10)
- c = Albero(5)
- d = Albero(7)
- e = Albero(11)
- f = Albero(16)
- g = Albero(20)
- a.sx = b
- a.dx = c
- c.dx = d
- b.sx = e
- d.sx = f
- d.dx = g
- flag = cerca(a,20)
Advertisement
Add Comment
Please, Sign In to add comment