Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cae11fe
Implement exercise binart-search-tree
rodrigocam Oct 8, 2017
d8256db
Add TreeNode class and binary search tree add method
rodrigocam Oct 8, 2017
5b65169
Add preorder, postorder and inorder traversal
rodrigocam Oct 8, 2017
06b303f
Add search method
rodrigocam Oct 8, 2017
b39e8d8
Add some tests
rodrigocam Oct 8, 2017
a5350dc
Add more testes, examle file and a readme
rodrigocam Oct 8, 2017
5604b08
Fix flake8 diretives
rodrigocam Oct 8, 2017
1013ec8
Add a new entry to config.json
rodrigocam Oct 8, 2017
5883681
Change new key place
rodrigocam Oct 8, 2017
ab2fa3e
Change search paramater name and add early if condition to exit if th…
rodrigocam Oct 10, 2017
1425ffc
Change exercise position in config.json
rodrigocam Oct 27, 2017
cb4e3bf
Merge branch 'master' into master
cmccandless Oct 27, 2017
fed194a
Merge branch 'master' into master
cmccandless Oct 27, 2017
9990ec2
Merge branch 'master' into master
cmccandless Oct 27, 2017
7192861
fix config.json syntax error
cmccandless Oct 27, 2017
3fe384e
Add blank line
rodrigocam Nov 3, 2017
62c5933
Add title at readme
rodrigocam Nov 3, 2017
49f6701
Add necessary info at readme
rodrigocam Nov 3, 2017
10627f2
Add skeletons for add and search methods
rodrigocam Nov 3, 2017
f4d558f
Change assert used by tests
rodrigocam Nov 3, 2017
5663d14
Add list method
rodrigocam Nov 3, 2017
56f971b
Change tests to include the new list method
rodrigocam Nov 3, 2017
fa1de56
Merge branch 'master' into master
cmccandless Nov 3, 2017
805557a
Fix flake8 guidelines
rodrigocam Nov 9, 2017
3b916a5
Change search and add method
rodrigocam Nov 9, 2017
1332fdc
Merge branch 'master' of https://github.com/rodrigocam/python
rodrigocam Nov 9, 2017
cd94b1f
Change variable name in search method and delete .cache directory
rodrigocam Nov 13, 2017
18c399f
Remove spaces on blank line
rodrigocam Nov 13, 2017
a01cb5a
Change parameter of search method
rodrigocam Nov 13, 2017
c054b29
Remove print methods
rodrigocam Nov 13, 2017
d43a2ba
Merge branch 'master' into master
Nov 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add search method
  • Loading branch information
rodrigocam committed Oct 8, 2017
commit 06b303f24fe6755aebbf519e905d7cb0015e05ac
18 changes: 15 additions & 3 deletions exercises/binary-search-tree/binary_search_tree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class TreeNode(object):
def __init__(self, value):
self.value = value
Expand All @@ -8,7 +7,6 @@ def __init__(self, value):
def __str__(self):
return str(self.value)

# lalal
class BinarySearchTree(object):
def __init__(self):
self.root = None
Expand All @@ -34,6 +32,19 @@ def add(self, value):
cur_node.right_node = TreeNode(value)
inserted = True

def search(self, searched_number):
cur_node = self.root
found = False
while not found:
if(searched_number < cur_node.value):
cur_node = cur_node.left_node
elif(searched_number > cur_node.value):
cur_node = cur_node.right_node
elif(searched_number == cur_node.value):
return cur_node
else:
raise ValueError("Element not found")

def print_inorder(self, node):
if(node is not None):
self.print_inorder(node.left_node)
Expand All @@ -50,4 +61,5 @@ def print_postorder(self, node):
if(node is not None):
self.print_preorder(node.left_node)
self.print_preorder(node.right_node)
print(node.value)
print(node.value)