-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (68 loc) · 2.13 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var inp_as=document.getElementById('a_size'),array_size=inp_as.value;
var inp_gen=document.getElementById("a_generate");
var inp_aspeed=document.getElementById("a_speed");
//var array_speed=document.getElementById('a_speed').value;
var butts_algos=document.querySelectorAll(".algos button");
var div_sizes=[];
var divs=[];
var margin_size;
var cont=document.getElementById("array_container");
cont.style="flex-direction:row";
//Array generation and updation.
inp_gen.addEventListener("click",generate_array);
inp_as.addEventListener("input",update_array_size);
function generate_array()
{
cont.innerHTML="";
for(var i=0;i<array_size;i++)
{
div_sizes[i]=Math.floor(Math.random() * 0.5*(inp_as.max - inp_as.min) ) + 10;
divs[i]=document.createElement("div");
cont.appendChild(divs[i]);
margin_size=0.1;
divs[i].style=" margin:0% " + margin_size + "%; background-color:blue; width:" + (100/array_size-(2*margin_size)) + "%; height:" + (div_sizes[i]) + "%;";
}
}
function update_array_size()
{
array_size=inp_as.value;
generate_array();
}
window.onload=update_array_size();
//Running the appropriate algorithm.
for(var i=0;i<butts_algos.length;i++)
{
butts_algos[i].addEventListener("click",runalgo);
}
function disable_buttons()
{
for(var i=0;i<butts_algos.length;i++)
{
butts_algos[i].classList=[];
butts_algos[i].classList.add("butt_locked");
butts_algos[i].disabled=true;
inp_as.disabled=true;
inp_gen.disabled=true;
inp_aspeed.disabled=true;
}
}
function runalgo()
{
disable_buttons();
this.classList.add("butt_selected");
switch(this.innerHTML)
{
case "Bubble":Bubble();
break;
case "Selection":Selection_sort();
break;
case "Insertion":Insertion();
break;
case "Merge":Merge();
break;
case "Quick":Quick();
break;
case "Heap":Heap();
break;
}
}