-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.py
More file actions
40 lines (31 loc) · 872 Bytes
/
tree.py
File metadata and controls
40 lines (31 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Tree():
def __init__(self):
self.root = {}
def size(self):
return self.bredth_first_size(self.root)
def bredth_first_size(self, children):
size = 0
for i in children:
size+=1
print(i)
for i in children:
size = size + self.bredth_first_size(children[i])
return size
def set_tree(self, add):
self.root = add
def root(self):
return self.root
def is_root(self,r):
if r is self.root:
return True
return False
def is_leaf(self, to_check):
if len(to_check) is 0:
return True
return False
if __name__ == '__main__':
tree = Tree()
to_add = {"1": {"2": {"3": {}, "4": {"5": {}}, "6": {}}
,"7": {"8": {"9": {}}}}}
tree.set_tree(to_add)
print (tree.size())