MCPcopy Index your code
hub / github.com/geekcomputers/Python / create_mirror_bst

Function create_mirror_bst

binary_search_trees/mirror_a_bst.py:5–19  ·  view source on GitHub ↗

Function to create a mirror of a binary search tree

(root: Optional[Node])

Source from the content-addressed store, hash-verified

3
4
5def create_mirror_bst(root: Optional[Node]) -> Optional[Node]:
6 """Function to create a mirror of a binary search tree"""
7
8 # If the tree is empty, return None
9 if root is None:
10 return None
11
12 # Recursively create the mirror of the left and right subtrees
13 left_mirror: Optional[Node] = create_mirror_bst(root.left)
14 right_mirror: Optional[Node] = create_mirror_bst(root.right)
15
16 # Swap left and right subtrees
17 root.left = right_mirror
18 root.right = left_mirror
19 return root

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected