The Same BST

Interface

class Sentinel
class SentinelNode
class TreeNode(data: int)
class BST
insert(element: int, bst: None | Sentinel | TreeNode = Sentinel) TreeNode

Recursively insert.

Parameters:
  • element – The element to be inserted.

  • bst – The subtree to insert, TreeNode or None.

Returns:

The root node of the current tree. But it first return SentinelNode.

build_tree(l: list) BST
check(node: TreeNode, i: int) bool
judge(bst: BST, list: list[int]) bool
reset(treenode: TreeNode | None) None
main()