Professional Documents
Culture Documents
BST
BST
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
def inorder_traversal(self):
result = []
self._inorder_traversal(self.root, result)
return result
# Example usage:
bst = BinarySearchTree()
keys = [50, 30, 70, 20, 40, 60, 80]
search_key = 40
if bst.search(search_key):
print(f"{search_key} found in the BST.")
else:
class Node:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
return root
# Example usage:
bst = BinarySearchTree()
keys = [50, 30, 70, 20, 40, 60, 80]