-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshitty_bst.py
54 lines (40 loc) · 1.04 KB
/
shitty_bst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from random import shuffle
class ShittyBst:
def __init__(self):
self.root = None
def insert(self, key, value):
newnode = self._insert(self.root, key, value)
if self.root == None:
self.root = newnode
def get(self, key):
pass
def in_order(self):
self._in_order(self.root)
def _insert(self, node, key, value):
if node == None:
return Node(key, value)
if key < node.key:
node.left = self._insert(node.left, key, value)
elif key > node.key:
node.right = self._insert(node.right, key, value)
return node
def _in_order(self, node):
if node == None:
return
self._in_order(node.left)
print node.key, node.value
self._in_order(node.right)
class Node:
def __init__(self, key, value):
self.key = key
self.value = value
self.left = None
self.right = None
if __name__ == '__main__':
bst = ShittyBst()
data = list(enumerate("this is a test dot split".split() ))
shuffle(data)
print data
for i, val in data:
bst.insert(i, val)
bst.in_order()