-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedBlackTree.html
More file actions
180 lines (153 loc) · 5.54 KB
/
RedBlackTree.html
File metadata and controls
180 lines (153 loc) · 5.54 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<header>
<title>REDBLACK TREE VISUALIZER</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=3.0, minimum-scale=0.86">
<!--style sheet-->
<link rel="stylesheet" href="Tree.css">
<!-- BOOTSTRAP -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</header>
<body onresize="resizeTree()">
<!-- BUTTONS START -->
<div class="head">
<div class="dropdown title">
<button class="dropbtn">
<span class="glyphicon glyphicon-menu-right " aria-hidden="true"></span>
REDBLACK TREE VISUALIZER.
</button>
<div class="dropdown-content">
<a href="BinaryTree.html"><span class="glyphicon glyphicon-menu-right " aria-hidden="true"></span> BINARY TREE VISUALIZER</a>
<a href="#"><span class="glyphicon glyphicon-menu-right " aria-hidden="true"></span> COMING SOON...</a>
</div>
</div>
<div class="row inputs">
<input type="text" class="input" id="insert" value="" placeholder="Add Value">
<span class="btn-wrap">
<button class="btn btn-primary a-btn-slide-text" onclick="addElement()">
<span class="glyphicon glyphicon-plus ico" aria-hidden="true"></span>
<span class="ico"><strong>Add</strong></span>
</button>
</span>
<input type="text" class="input" id="delete" value="" placeholder="Delete Value">
<span class="btn-wrap">
<button class="btn btn-primary a-btn-slide-text" onclick="deleteElement()">
<span class="glyphicon glyphicon-trash ico" aria-hidden="true"></span>
<span><strong>Delete</strong></span>
</button>
</span>
<input type="text" class="input" id="search" value="" placeholder="Search Value">
<span class="btn-wrap">
<button class="btn btn-primary a-btn-slide-text" onclick="findElement()">
<span class="glyphicon glyphicon-eye-open ico" aria-hidden="true"></span>
<span><strong>Search</strong></span>
</button>
</span>
<span class="btn-wrap">
<button class="btn btn-primary a-btn-slide-text" onclick="reset()">
<span class="glyphicon glyphicon-repeat ico" aria-hidden="true"></span>
<span><strong>Reset</strong></span>
</button>
</span>
</div>
</div>
<!-- BUTTONS END -->
<!-- TREE AREA -->
<div id="tree">
<div id="addNode"><h1>Add Nodes To Build Tree.</h1></div>
</div>
<div id="branch">
</div>
<!-- TREE END -->
<!------------- Draggable DIV ------------->
<div id="mydiv" style="visibility:hidden;">
<div id="mydivheader">SEARCH RESULTS</div>
<div id="mydivbody"></div>
</div>
<script>
document.getElementById('mydiv').style.visibility = "hidden";
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "header")) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
}
</script>
<!-- CREATE TREE FUNCTIONS -->
<script src="RedBlackTree.js"></script>
<script>
var t = new RedBlackTree();
function addElement() {
var value = document.getElementById('insert').value;
t.insert(value);
t.ring(value);
t.printTree(value);
}
function deleteElement() {
var value = document.getElementById('delete').value;
t.deleteNode(value);
// t.ring(value);
//t.printTree(value);
}
function findElement() {
var value = document.getElementById('search').value;
const node = t.search(value);
document.getElementById('mydiv').style.visibility = "visible";
document.getElementById('mydivbody').innerHTML = '';
document.getElementById('mydivbody').innerHTML += '<p>ID : #'+node.id+'</p>';
document.getElementById('mydivbody').innerHTML += '<p>DATA : '+node.data+'</p>';
document.getElementById('mydivbody').innerHTML += '<p>COLOR : '+node.color+'</p>';
document.getElementById('mydivbody').innerHTML += '<p>CHILDREN : '+node.children+'</p>';
document.getElementById('mydivbody').innerHTML += '<p>CHILDREN-LEFT : '+node.childrenLeft+'</p>';
document.getElementById('mydivbody').innerHTML += '<p>CHILDREN-RIGHT : '+node.childrenRight+'</p>';
dragElement(document.getElementById("mydiv"));
}
function reset() {
t.clearCanvas();
t = new RedBlackTree();
t.clearCanvas();
}
function resizeTree(){
t.shiftTree();
}
</script>
</body>
</html>