-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.html
58 lines (53 loc) · 1.5 KB
/
server.html
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
55
56
57
58
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>traceface</title>
<link rel="stylesheet" href="server.css">
</head>
<body>
<form method="post" action="/trace">
<div class="instructions">input some code and click trace</div>
<textarea name="code">
class Node(object):
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def __repr__(self):
return f'Node({self.value})'
class BinaryTree(object):
def __init__(self, root):
self.root = Node(root)
def print_tree(self, traversal_type):
if traversal_type == "preorder":
return self.pre_order_print(self.root, "")
else:
print("Traversal type" + str(traversal_type)+ " is not supported")
def pre_order_print(self, start, traversal):
if start:
traversal += (str(start.value) + "-")
traversal = self.pre_order_print(start.left, traversal)
traversal = self.pre_order_print(start.right, traversal)
return traversal
tree = BinaryTree(21)
tree.root.left = Node(8)
tree.root.left.left = Node(2)
tree.root.left.right = Node(19)
tree.root.right = Node(50)
tree.root.right.left = Node(36)
tree.root.right.right = Node(69)
print(tree.print_tree("preorder"))
</textarea>
<input type="submit" value="trace">
<div class="paste">
<p>or paste some code to permalink to the trace</p>
https://cpy.pt/<input type="text" name="paste">
</div>
<input type="submit" value="trace">
</form>
<div class="github">
<a href="https://github.com/raylu/traceface">github.com/raylu/traceface</a>
</div>
</body>
</html>