mirror of
https://github.com/jlengrand/Coding4Interviews.git
synced 2026-03-10 08:11:24 +00:00
Prepares binary search tree data structure.
This commit is contained in:
29
01_binary_search_trees/bst.py
Normal file
29
01_binary_search_trees/bst.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
Binary Search Tree Implementation
|
||||
@jlengrand
|
||||
2013/07
|
||||
"""
|
||||
|
||||
class BinarySearchTree():
|
||||
"""
|
||||
Defines a complete binary search Tree.
|
||||
A binary search tree has a root node.
|
||||
We also add a size to the search tree, that corresponds to the number of
|
||||
nodes it has.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.size = 0
|
||||
self.root_node = None
|
||||
|
||||
class BinarySearchNode():
|
||||
"""
|
||||
Defines any node of the Binary Search Tree.
|
||||
A node has at most 2 children, and it has a value.
|
||||
It also must have a parent
|
||||
"""
|
||||
def __init__(self, value, parent):
|
||||
self.parent_node = parent
|
||||
self.node_value = value
|
||||
|
||||
self.left_child = None
|
||||
self.right_child = None
|
||||
5
01_binary_search_trees/bst_test.py
Normal file
5
01_binary_search_trees/bst_test.py
Normal file
@@ -0,0 +1,5 @@
|
||||
"""
|
||||
Unit tests for the binary search tree data structure
|
||||
@jlengrand
|
||||
2013/07
|
||||
"""
|
||||
Reference in New Issue
Block a user