-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.js
More file actions
113 lines (107 loc) · 3.37 KB
/
sort.js
File metadata and controls
113 lines (107 loc) · 3.37 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
const size = document.querySelector("#size");
const speed = document.querySelector("#speed");
const sizeText = document.querySelector("label[for='size']> span");
const speedText = document.querySelector("label[for='speed']> span");
const elements = document.getElementsByClassName("elements")[0];
const width = parseFloat(window.getComputedStyle(elements).width);
const height = parseFloat(window.getComputedStyle(elements).height);
// about
const aboutPara = document.querySelector(".about>p");
const aboutCode = document.querySelector("#code");
// table
const worstTC = document.querySelector(".worst>td");
const averageTC = document.querySelector(".average>td");
const bestTC = document.querySelector(".best>td");
const spaceC = document.querySelector(".spaceComplexity>td");
// code
const javaButton = document.querySelector(".java");
const javaScriptButton = document.querySelector(".js");
size.value = 50;
sizeText.innerText = size.value;
speed.value = 5;
speedText.innerText = speed.value;
let widthDiv = width / Number(size.value);
formationOfBars(size.value, widthDiv);
size.addEventListener("input", () => {
sizeText.innerText = size.value;
widthDiv = width / Number(size.value);
formationOfBars(Number(size.value), widthDiv);
});
speed.addEventListener("input", () => {
speedText.innerText = speed.value;
});
function pageUpdation(name) {
const head = document.getElementById("headx");
head.innerText = name;
if (name == "Bubble Sort") {
descriptionBubbleSort();
} else if (name == "Selection Sort") {
descriptionSelectionSort();
} else if (name == "Insertion Sort") {
descriptionInsertionSort();
} else if (name == "Quick Sort") {
descriptionQuickSort();
} else if (name == "Merge Sort") {
descriptionMergeSort();
} else if (name == "Heap Sort") {
descriptionHeapSort();
}
}
function formationOfBars(size, widthDiv) {
elements.innerText = "";
for (let i = 0; i < size; i++) {
let h = Math.random() * 10 + 1;
arr.push(h);
const div = document.createElement("div");
div.classList.add("ele");
elements.insertAdjacentElement("beforeend", div);
div.style.height = `${h * 30}px`;
div.style.width = `${widthDiv}px`;
div.id = `ele${i}`;
}
}
async function delay(sec) {
return new Promise((res) => {
setTimeout(() => {
return res();
}, sec * 1000);
});
}
function error(ele1, ele2) {
ele1
? (ele1.style.background =
"linear-gradient(to top, #ff0844 0%, #ffb199 100%)")
: "";
ele2
? (ele2.style.background =
"linear-gradient(to top, #ff0844 0%, #ffb199 100%)")
: "";
}
function successful(ele1, ele2) {
ele1
? (ele1.style.background =
"linear-gradient( 180deg, rgba(155,254,23,1) 45.5%, rgba(36,243,8,1) 97.9% )")
: "";
ele2
? (ele2.style.background =
"linear-gradient( 180deg, rgba(155,254,23,1) 45.5%, rgba(36,243,8,1) 97.9% )")
: "";
}
function reset(ele1, ele2) {
ele1
? (ele1.style.background =
"radial-gradient( circle 1224px at 10.6% 8.8%, rgba(255,255,255,1) 0%, rgba(153,202,251,1) 100.2% )")
: "";
ele2
? (ele2.style.background =
"radial-gradient( circle 1224px at 10.6% 8.8%, rgba(255,255,255,1) 0%, rgba(153,202,251,1) 100.2% )")
: "";
}
VanillaTilt.init(document.querySelector(".complexityTable"), {
max: 10,
speed: 400,
});
VanillaTilt.init(document.querySelector(".code"), {
max: 10,
speed: 400,
});