-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble.html
78 lines (64 loc) · 2.04 KB
/
bubble.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<style>
body {padding-top:50px ; text-align: center;; margin-top: auto;background-color:#0c7b93}
div {color: white; }
</style>
</head>
<body>
<h1>BUBBLE SORT</h1>
<button onclick="location.href='bubblecode.html'">See Bubble Sort C++ Code</button> <br /><br />
<button onclick="location.href='index.html'">Go to Home Page</button> <br /><br />
<input placeholder="ADD ONE NUMBER AT A TIME" type="text" id="text1" size="30"></input>
<input type="button" id="button1" value="ADD" onclick="add_element_to_array(); disp() " ></input><br><br>
<input type="button" id="button2" value="SORT" onclick="display_array();"><br /><br />
<button onclick="location.href='bubble.html'">RESET</button><br />
<div id="Temp">
</div>
<div id="Result"></div>
<script type="text/javascript">
var x = 0;
var array = Array();
function add_element_to_array()
{
array[x] = parseFloat(document.getElementById("text1").value);
x++;
document.getElementById("text1").value = "";
}
function disp(){
var t="<hr/>";
for(var i=0;i<array.length;i++){
t += "Element " + i + " = " + array[i] + "<br/>";
}
document.getElementById("Temp").innerHTML = t;
}
function display_array()
{
var e = "<hr/>";
var start = performance.now();
for(var i=0;i<array.length;i++){
for(var j=i+1;j<array.length;j++){
if(array[i]>array[j])
{
var temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
var end = performance.now();
var time = end - start;
e+="SORTED BY BUBBLE SORT"+"<br />"
for (var y=0; y<array.length; y++)
{
e += "Element " + y + " = " + array[y] + "<br/>";
}
e+="TIME COMPLEXITY = O(N^2)"+"<br/>"+"TIME TAKEN = "+time+" ms<br/>";
document.getElementById("Result").innerHTML = e;
}
</script>
</body>
</html>