This repository was archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
221 lines (198 loc) · 8.12 KB
/
index.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Visualizing searching algos</title>
<link rel="stylesheet" type="text/css" href="index.css" />
</head>
<body>
<style></style>
<h1><span class='important_letter'>S</span>earching <span class='important_letter'>A</span>lgorithms</h1>
<div id="theme_div">
<table>
<tr>
<td><label for="theme_in">Theme: </label></td>
<td><select id="theme_in">
<option value="light">Light</option>
<option value="dark">Dark</option>
</select></td>
</tr>
</table>
</div>
<div id="score_div">
<table>
<tr>
<td>Comparisons</td>
<td id="comparisons">0</td>
</tr>
<tr>
<td>Runtime [s]</td>
<td id="runtime">0</td>
</tr>
</table>
</div>
<div id="algo_info">
<div id="algorithm_div">-</div>
<table>
<tr>
<td>Searched element: </td>
<td id="searched_element">-</td>
</tr>
<tr>
<td>Current element: </td>
<td id="current_element">-</td>
</tr>
</table>
</div>
<table id="algorithm_settings">
<tr>
<td><label for="algorithm_input">Algorithm: </label></td>
<td><select id="algorithm_input">
<option value="linear_search">Linear Search</option>
<option value="double_linear_search">Double Linear Search</option>
<option value="binary_search">Binary Search</option>
<option value="jump_search">Jump Search</option>
<option value="interpolation_search">Interpolation Search</option>
<option value="exponential_search">Exponential Search</option>
<option value="fibonacci_search">Fibonacci Search</option>
</select></td>
</tr>
<tr>
<td><label for="show_sorting">Display sorting: </label></td>
<td><input id="show_sorting" type="checkbox" checked /></td>
</tr>
<tr>
<td><label for="amount_input">Amount: </label></td>
<td><input id="amount_input" type="number" placeholder="e.g.: 1000" /></td>
</tr>
<tr>
<td><label for="sorting_pause_input">Sorting Pause [ms]: </label></td>
<td><input id="sorting_pause_input" type="number" placeholder="e.g.: 100" /></td>
</tr>
<tr>
<td><label for="pause_input">Searching Pause [ms]: </label></td>
<td><input id="pause_input" type="number" placeholder="e.g.: 100" /></td>
</tr>
<tr>
<td><label for="lower_input">Lower boundry: </label></td>
<td><input id="lower_input" type="number" placeholder="e.g.: 10" /></td>
</tr>
<tr>
<td><label for="upper_input">Upper boundry: </label></td>
<td><input id="upper_input" type="number" placeholder="e.g.: 10000" /></td>
</tr>
<tr>
<td><label for="display_function">Display option: </label></td>
<td>
<select id="display_function">
<option value="display_pillars">As pillars</option>
</select>
</td>
</tr>
<tr>
<td><label for="create_func">Creation options: </label></td>
<td>
<select id="create_func">
<option value="create_random">Completely random</option>
<option value="create_semi_random">"Semi" random</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="button" id="submit_start" value="Start!" /></td>
</tr>
</table>
<div id="canvas_div">
<canvas id="main" width="800" awidth="800" height="700"></canvas>
</div>
<script src="algos/binary_search.js"></script>
<script src="algos/interpolation_search.js"></script>
<script src="algos/linear_search.js"></script>
<script src="algos/jump_search.js"></script>
<script src="algos/exponential_search.js"></script>
<script src="algos/fibonacci_search.js"></script>
<script src="algos/double_linear_search.js"></script>
<script src="sorting_algos/quick_sort.js"></script>
<script src="./visualize.js"></script>
<script>
window.onload = e => {
// stuff ...
cnvs = document.getElementById('main');
ctx = cnvs.getContext('2d');
canvas = {
width: document.getElementById('main').attributes["awidth"].value,
height: document.getElementById('main').height
};
document.onkeyup = e => {
if (e.keyCode == 13 && document.getElementById('algorithm_settings').style.display == "block") {
document.getElementById('submit_start').click();
}
};
document.getElementById('theme_in').onchange = e => {
changeTheme(e.target.value);
};
document.getElementById('submit_start').onclick = e => {
let algo = document.getElementById('algorithm_input').value,
amount = document.getElementById('amount_input').value,
sorting_pause_ms = document.getElementById('sorting_pause_input').value,
pause_ms = document.getElementById('pause_input').value,
lower = document.getElementById('lower_input').value,
upper = document.getElementById('upper_input').value,
display_func = document.getElementById('display_function').value,
create_func = document.getElementById('create_func').value;
let show_sorting = document.getElementById('show_sorting').checked;
glob_show_sorting = show_sorting;
if (amount != '')
glob_amount = parseInt(amount);
if (sorting_pause_ms != '')
glob_sorting_sleep_time = parseInt(sorting_pause_ms);
if (pause_ms != '')
glob_sleep_time = parseInt(pause_ms);
if (lower != '')
glob_lower = parseInt(lower);
if (upper != '')
glob_upper = parseInt(upper);
switch (display_func) {
case 'display_pillars':
glob_search_display_func = display_pillars;
break;
}
switch (create_func) {
case 'create_random':
glob_random_func = create_array_random;
break;
case 'create_semi_random':
glob_random_func = create_array_semi_random;
break;
}
glob_stime = (new Date()).getTime();
switch (algo) {
case 'binary_search':
doSearchingAlgo(doBinarySearch);
break;
case 'interpolation_search':
doSearchingAlgo(doInterpolationSearch);
break;
case 'linear_search':
doSearchingAlgo(doLinearSearch);
break;
case 'jump_search':
doSearchingAlgo(doJumpSearch);
break;
case 'exponential_search':
doSearchingAlgo(doExponentialSearch);
break;
case 'fibonacci_search':
doSearchingAlgo(doFibonacciSearch);
break;
case 'double_linear_search':
doSearchingAlgo(doDoubleLinearSearch);
break;
}
};
visualize_init();
};
</script>
</body>
</html>