-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.html
86 lines (74 loc) · 2.18 KB
/
count.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
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<style>
body {padding-top:50px ; text-align: center;background-color:#0c7b93; margin-top: auto;}
div {color: white; }
</style>
</head>
<body>
<h1>COUNT SORT</h1>
<button onclick="location.href='countcode.html'">See Count Sort C++ Code</button> <br /><br />
<button onclick="location.href='index.html'">Go to Home Page</button> <br /><br />
<div class="">
ENTER WHOLE NUMBERS
</div>
<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='count.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] = parseInt(document.getElementById("text1").value);
// alert("Element: " + array[x] + " Added at index " + x);
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 helper = [];
var start = performance.now();
for(var i = 0; i<array.length; i++){
if(!helper[array[i]]){
helper[array[i]] = 1;
}else{
helper[array[i]] += 1;
}
}
var arr = [];
for(i in helper){
while(helper[i]>0){
arr.push(i);
helper[i]--;
}
}
var end = performance.now();
var time = end - start;
e+="SORTED BY COUNT SORT"+"<br />"
for (var y=0; y<arr.length; y++)
{
e += "Element " + y + " = " + arr[y] + "<br/>";
}
e+="TIME COMPLEXITY = O(N)"+"<br/>"+"TIME TAKEN = "+time+"ms<br/>";
document.getElementById("Result").innerHTML = e;
}
</script>
</body>
</html>