Basic unit in each type of binary tree.
Source code: binaryNode.py
treestructure.BinaryNode(order=time.time(), value=None)
Module of basic binary node.
- order: float or int
It's the priority when constructing the tree structure. Default order is current timestamp. - value: Any
It can be anything you want to store. Default value is None. - leftChildNode: BinaryNode or None
Save the pointer points to left node. - rightChildNode: BinaryNode or None
Save the pointer points to right node. - parentNode: BinaryNode or None
Save the pointer points to parent node.Note: You can't modify order if node has been added into tree. It'll raise error.
leftChildNode, rightChildNode and parentNode are read-only.
You can edit value anytime.
BinaryNode.package()
Package node information and return.
- return: dict
A dictionary contains node's order, value, left child, right child and parent.
>>> node = treestructure.BinaryNode(25, 'Michael Jackson') # Create node
>>> node.order
25
>>> node.value
'Michael Jackson'
>>> pprint.pprint(node.package(), sort_dicts=False) # Display node
{'order': 25,
'value': 'Michael Jackson',
'leftChildNode': {},
'rightChildNode': {},
'parentNode': {}}
>>> node.order = 35 # Modify node
>>> node.value = 'Prince' # Modify node
>>> node.order
35
>>> node.value
'Prince'