-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtnode.py
More file actions
44 lines (39 loc) · 1.09 KB
/
Copy pathbtnode.py
File metadata and controls
44 lines (39 loc) · 1.09 KB
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
41
42
43
44
"""
CSCI-603: Trees (week 10)
Author: Sean Strout @ RIT CS
This is an implementation of a binary tree node.
"""
class BTNode:
"""
A binary tree node contains:
:slot val: A user defined value
:slot left: A left child (BTNode or None)
:slot right: A right child (BTNode or None)
"""
__slots__ = 'val', 'left', 'right'
def __init__(self, val, left=None, right=None):
"""
Initialize a node.
:param val: The value to store in the node
:param left: The left child (BTNode or None)
:param right: The right child (BTNode or None)
:return: None
"""
self.val = val
self.left = left
self.right = right
def testBTNode():
"""
A test function for BTNode.
:return: None
"""
left = BTNode(10)
right = BTNode(20)
parent = BTNode(30)
parent.left = left
parent.right = right
print('parent (30):', parent.val)
print('left (10):', parent.left.val)
print('right (20):', parent.right.val)
if __name__ == '__main__':
testBTNode()