Binary Tree Code Summary
Binary Tree Code Summary
class Node: → Defines a class representing a single node in the binary tree.
def __init__(self): → Constructor initializes a node with data and two child pointers.
self.Data = "" → Stores the data value for the node (initially empty).
self.Left = None → Pointer (index) to the left child node (initially None).
self.Right = None → Pointer (index) to the right child node (initially None).
def initialiseTree(): → Initializes the tree with empty nodes and sets up free list.
for i in range(size - 1): → Loop to link each node to the next as a free list.
Tree[size - 1].Left = None → Last node in the free list points to None.
def FindInsertionPoint(NewData): → Finds where to insert new data in the binary tree.
while Pointer is not None: → Keep looping until a null pointer is found.
return Parent, Direction → Return insertion point and which direction to insert.
def addToTree(NewData): → Adds a new node with given data to the binary tree.
while Pointer is not None: → Loop until we find or exhaust the tree.