-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
173 lines (122 loc) · 5.54 KB
/
index.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<html>
<head>
<title>sort.js</title>
<script src='js/lib/jquery-1.11.3.min.js'></script>
<script src='js/lib/bootstrap.min.js'></script>
<script src='js/sort.js'></script>
<link href='css/lib/bootstrap.min.css' rel='stylesheet'>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" type="text/css" href="css/styleRadioButton.css"/>
<style>
</style>
</head>
<body style="background-color: ; margin:50px" >
<div class='container-fluid' style="margin-left: 20px; background-color:">
<div class='row'>
<div class='col-xs-3' style="background-color:; padding-bottom:50px; height:80%; border:5px solid #3B99A5; border-radius: 25px; border-style:">
<div class='form-group'>
<br>
</div>
<br>
<div class='form-group'>
<label for='#algo-select'>Algorithm</label>
<select class='form-control' id='algo-select' style="">
<option value='quicksort' data-description="Worst-complexity: O(n^2)<br>
Average-complexity: O(N*logN)<br>Best-complexity: O(N*logN)
<br> Space-complexity: in-place">Quicksort</option>
<option value='bubblesort' data-description="Worst-complexity: O(n^2)<br>
Average-complexity: O(n^2)<br>Best-complexity: O(n)<br> Space-complexity: O(1)">
Bubble sort</option>
<option value='selectionsort' data-description="Worst-complexity: O(n^2)<br>
Average-complexity: O(n^2)<br>Best-complexity: O(n^2)<br> Space-complexity: O(1)">Selection sort</option>
<option value='insertionsort' data-description="Worst-complexity: O(n^2)<br>
Average-complexity: O(n^2)<br>Best-complexity: O(n)<br> Space-complexity: O(1)">Insertion sort</option>
<option value='heapsort' data-description="Worst-complexity: O(N*logN)<br>
Average-complexity: O(N*logN)<br>Best-complexity: O(N*logN)<br> Space-complexity: O(1)">Heapsort</option>
<option value='mergesort' data-description="Worst-complexity: O(N*logN)<br>
Average-complexity: O(NlogN)<br>Best-complexity: O(N*logN)<br> Space-complexity: O(n)">Merge sort</option>
</select>
<span id="description" style=""></span>
</div>
<div class="slidecontainer">
<p><b>Array Size: </b><span id="demo"></span></p>
<input type="range" min="50" max="300" value="50" class="slider" id='array-size'>
</div>
<br>
<div class="slidecontainer">
<p><b>Speed: </b><span id="demo2"></span> (ms) </p>
<input type="range" min="1" max="1000" value="1" class="slider" id='interval'>
</div>
<br>
<div class='text-center'>
<button class='btn btn-lg btn-primary' id='start-btn'>Start</button>
</div>
</div>
<div class='col-xs-9' id='canvas-div' style="margin-right:50px; width:70%; height:80%">
<canvas width="1920px" height="1080px" id="main-canvas" style="border:5px solid #3B99A5; border-radius: 25px; border-style:" >
</div>
</div>
</div>
<!--Round Slider-->
<script>
var slider = document.getElementById('array-size');
var output = document.getElementById("demo");
output.innerHTML = slider.value;
slider.oninput = function() {
output.innerHTML = this.value;
}
</script>
<script>
var slider2 = document.getElementById('interval');
var output2 = document.getElementById("demo2");
output2.innerHTML = slider2.value;
slider2.oninput = function() {
output2.innerHTML = this.value;
}
</script>
<!--description-->
<script>
$('#algo-select').change(function(){
var $selected = $(this).find(':selected');
$('#description').html($selected.data('description'));
}).trigger('change');
</script>
<script>
$(function() {
var temp = null;
// Make the canvas fit the available space
var resize_canvas = function() {
$('#main-canvas').width($('#canvas-div').width());
}
resize_canvas();
$(window).resize(resize_canvas);
$('#start-btn').click(function() {
if (temp !== null) temp.cancel();
var n = parseInt($('#array-size').val());
var interval = parseInt($('#interval').val());
var algo = $('#algo-select').val();
var sort_fn = sorting.get_sort_fn(algo);
var ary = [];
// Values pushed to the array should be in the range (0, 1] so that
// all bars have a visible representation
for (var i = 0; i < n; i++) {
// Math.random() can't be used directly because it returns values
// in the range [0, 1)
let val = Math.random()
// Move the value into the range [0, 100) and make it an integral
// value
val *= 100
val = Math.floor(val)
// Move the value into the range (0, 100] from [0, 100)
val += 1;
// Push a value in the range (0, 1]
ary.push(val / 100);
}
var canvas = document.getElementById('main-canvas');
temp = new sorting.AnimatedArray(ary, canvas, interval);
sort_fn(temp);
});
});
</script>
</body>
</html>