-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.py
30 lines (24 loc) · 798 Bytes
/
tree.py
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
""" Tree class and functions
"""
class Tree:
"""
A bare-bones Tree ADT that identifies the root with the entire tree.
=== Attributes ===
@param object value: value of root node
@param list[Tree|None] children: child nodes
"""
def __init__(self, value, children=None):
"""
Create Tree self with content value and 0 or more children
@param Tree self: this tree
@param object value: value contained in this tree
@param list[Tree|None] children: possibly-empty list of children
@rtype: None
"""
self.value = value
self.children = children[:] if children is not None else []
def __str__(self):
return str(self.value)
if __name__ == '__main__':
import doctest
doctest.testmod()