Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arbore = { "value" : 8,
- "left":
- {
- "value": 9, "left":
- {
- "value": 3, "left":
- {
- "value": 14, "left": None, "right": None
- }, "right":
- {
- "value": 2, "left": None, "right":
- {
- "value": 5, "left": None, "right": None
- }
- }
- }, "right": None
- },
- "right":
- {
- "value": 20, "left":
- {
- "value": 7, "left": None, "right": None
- }, "right":
- {
- "value": 15, "left":
- {
- "value": 30, "left":
- {
- "value": 22, "left": None, "right": None
- }, "right":
- {
- "value": 27, "left": None, "right": None
- }
- }, "right": None
- }
- }
- }
- def nrNodes(tree):
- r = 0
- def utilNrNodes(tree):
- nonlocal r
- r += 1
- if tree['left'] is not None:
- utilNrNodes(tree['left'])
- if tree['right'] is not None:
- utilNrNodes(tree['right'])
- utilNrNodes(tree)
- return r
- print(nrNodes(arbore))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement