-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
46 lines (33 loc) · 1.17 KB
/
main.js
File metadata and controls
46 lines (33 loc) · 1.17 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
import TrackedArray from "./Assets/Visual/TrackedArray.js";
import { animate, reset } from "./Assets/Visual/Visualize.js";
import insertionSort from "./Assets/Sorting/insertionSort.js";
import bubbleSort from "./Assets/Sorting/bubbleSort.js";
function init() {
let speedSlider = document.getElementById("speed");
window.sizeSlider = document.getElementById("size");
let arrContainer = document.getElementById("list");
let sortButton = document.getElementById("sortButton");
window.arr = new TrackedArray(generateRandomArray(sizeSlider.value));
reset();
sizeSlider.oninput = () => init();
arrContainer.innerHTML = arr.arr;
if (sorter == 'insertion') {
insertionSort(arr);
} else if (sorter == 'bubble') {
bubbleSort(arr);
}
}
function generateRandomArray(size) {
// return [8,0,7,12,20,13,11,31,34,2] // for quickSort
return Array.from({ length: size }, () => Math.floor(Math.random() * 40));
}
window.callRender = function(arr) {
console.log(arr);
animate(arr.full_copies, arr.getActivity());
}
window.setSorter = function(str) {
window.sorter = str;
init();
}
window.sorter = 'insertion';
init()