Removing bst implementation, tree challenges will be more independent for simplicity.

This commit is contained in:
Donne Martin 2015-08-01 16:46:40 -04:00
parent 4fc25a0a98
commit a0b6421f79
2 changed files with 0 additions and 60 deletions

View File

@ -1,53 +0,0 @@
from collections import deque
class Node(object):
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def insert(self, data):
if data <= self.data:
if self.left is None:
self.left = Node(data)
else:
self.left.insert(data)
else:
if self.right is None:
self.right = Node(data)
else:
self.right.insert(data)
def in_order_traversal(self, visit_func):
if self.left is not None:
self.left.in_order_traversal(visit_func)
visit_func(self.data)
if self.right is not None:
self.right.in_order_traversal(visit_func)
def pre_order_traversal(self, visit_func):
visit_func(self.data)
if self.left is not None:
self.left.pre_order_traversal(visit_func)
if self.right is not None:
self.right.pre_order_traversal(visit_func)
def post_order_traversal(self, visit_func):
if self.left is not None:
self.left.post_order_traversal(visit_func)
if self.right is not None:
self.right.post_order_traversal(visit_func)
visit_func(self.data)
def bfs(self, visit_func):
queue = deque()
queue.append(self)
while len(queue) > 0:
node = queue.popleft()
visit_func(node.data)
if node.left is not None:
queue.append(node.left)
if node.right is not None:
queue.append(node.right)

View File

@ -73,13 +73,6 @@
"## Code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note: `in_order_traversal` is provided for testing purposes."
]
},
{
"cell_type": "code",
"execution_count": null,