-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.py
32 lines (28 loc) · 954 Bytes
/
driver.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
from balancedTernarySearchTree.balancedTernarySearchTree import balancedTernarySearchTree
def errorHandle(value=None):
print('Invalid Instruction')
tree = balancedTernarySearchTree()
actions = {
"push": tree.push,
"remove": tree.remove,
"search": tree.search,
"print": tree.print,
"printLevelOrder": tree.printLevelOrder
}
def readInput():
with open('input.txt','r') as file: #change name of input file to have other file as input
for line in file:
values = line.split()
function = values[0]
if len(values) > 1:
value = values[1]
if '.' in value:
value = float(value)
else:
value = int(value)
actions.get(function,errorHandle)(value)
else:
actions.get(function,errorHandle)()
file.close()
if __name__ == '__main__':
readInput()