-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·60 lines (42 loc) · 1.31 KB
/
app.js
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
59
60
var t;
function eventTreeTypeChange() {
let option = document.getElementById("TreeType").value;
if (option == "bst") {
t = new Tree();
} else if (option == "avl") {
t = new AvlTree();
}
document.getElementById("Steps").innerHTML = "";
updateInfomation(t);
}
function eventInsertFieldChange(event) {
if (event.keyCode === 13) {
// Cancel the default action, if needed
event.preventDefault();
let field = document.getElementById("InsertField");
let value = field.value;
field.value = "";
value = value.replace(/\s/gi, "");
let nodes = value.split(",");
for (let idx in nodes) {
const node = nodes[idx];
if (node != "") t.insert(node);
}
}
}
function eventDeleteFieldChange(event) {
if (event.keyCode === 13) {
// Cancel the default action, if needed
event.preventDefault();
let field = document.getElementById("DeleteField");
let value = field.value;
field.value = "";
value = value.replace(/\s/gi, "");
nodes = value.split(",");
for (let idx in nodes) {
const node = nodes[idx];
if (node != "") t.remove(node);
}
}
}
eventTreeTypeChange(); // trigger once at the beginning