-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertion_sort.js
More file actions
64 lines (51 loc) · 1.6 KB
/
insertion_sort.js
File metadata and controls
64 lines (51 loc) · 1.6 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
/*
*****************
DONE BY:- TUMMALA KETHAN
*****************
*/
function Insertion()
{
//Setting Time complexities
document.getElementById("Time_Worst").innerText="O(N^2)";
document.getElementById("Time_Average").innerText="Θ(N^2)";
document.getElementById("Time_Best").innerText="Ω(N)";
//Setting Space complexity
document.getElementById("Space_Worst").innerText="O(1)";
c_delay=0;
for(var j=0;j<array_size;j++)
{
div_update(divs[j],div_sizes[j],"yellow");//Color update
var key= div_sizes[j];
var i=j-1;
while(i>=0 && div_sizes[i]>key)
{
div_update(divs[i],div_sizes[i],"red");//Color update
div_update(divs[i+1],div_sizes[i+1],"red");//Color update
div_sizes[i+1]=div_sizes[i];
div_update(divs[i],div_sizes[i],"red");//Height update
div_update(divs[i+1],div_sizes[i+1],"red");//Height update
div_update(divs[i],div_sizes[i],"blue");//Color update
if(i==(j-1))
{
div_update(divs[i+1],div_sizes[i+1],"yellow");//Color update
}
else
{
div_update(divs[i+1],div_sizes[i+1],"blue");//Color update
}
i-=1;
}
div_sizes[i+1]=key;
for(var t=0;t<j;t++)
{
div_update(divs[t],div_sizes[t],"green");//Color update
}
}
div_update(divs[j-1],div_sizes[j-1],"green");//Color update
enable_buttons();
}
/*
*****************
DONE BY:- TUMMALA KETHAN
*****************
*/