forked from artengin/artengin.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
236 lines (234 loc) · 8.7 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>Методы сортировки массивов</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.v.0.4.css">
<link rel="icon" href="img/favicon.ico">
</head>
<body>
<div class='sort-blocks'>
<h1>Методы сортировки массивов:</h1>
<select id="method">
<option value="bubble">Пузырьковая сортировка</option>
<option value="mixing">Сортировка перемешиванием</option>
<option value="dwarf">Гномья сортировка</option>
<option value="comb">Сортировка расческой</option>
<option value="selection">Сортировка выбором</option>
<option value="double-selection">Двухсторонняя сортировка выбором</option>
</select>
<p class="title-complete-array">Заполните массив цифрами:</p>
<div class='input-block'>
<span class="btn-input-block">
<img src="img/random.png" alt="Radom Array" title="Create random array" class="btn-random">
</span><span>[</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'><span>,</span>
<input type='number' onkeydown="javascript: return event.keyCode == 69 ? false : true" oninput="checkLength(this)" class='input-sort'>
<span>]</span>
<span class="btn-input-block">
<img src="img/clear.png" alt="Clear Array" title="Clear array value" class="btn-clear">
</span>
</div>
<p class="speed-block">Скорость итерации: <span id="speed-btn"><span class="speed-btn">0.1</span><span class="speed-btn">0.2</span><span class="speed-btn active">0.4</span><span class="speed-btn">0.6</span><span class="speed-btn">0.8</span><span class="speed-btn">1</span></span></p>
<button id='btn-sort'>сортировать</button>
<div class="code-block" id="code-open">
<span class="code-title">Code JS:</span>
<pre id="code-bubble">
//Сортировка пузырьковым методом
const arraySorting = () => {
let array = [37, 2, 89, 65, 1, 28, 41];
for(out = array.length - 1; out > 0; out--){
for (let i = 0; i < out; i++) {
if (array[i] > array[i + 1]) {
temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
}
}
}
return array;
}
console.log(arraySorting());
</pre>
<pre id="code-mixing">
//Сортировка перемешиванием
const arraySorting = () => {
let array = [37, 2, 89, 65, 1, 28, 41];
let start = 0;
let stop = array.length - 1;
do{
swap = false;
for (i = start; i < stop; i++) {
if (array[i] > array[i + 1]) {
temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
swap = true;
}
}
for (l = stop - 1; l >= start; l--) {
if (array[l] > array[l + 1]) {
temp = array[l + 1];
array[l + 1] = array[l];
array[l] = temp;
swap = true;
}
}
start++;
stop--;
} while (swap);
return array;
}
console.log(arraySorting());
</pre>
<pre id="code-dwarf">
//Гномья сортировка
const arraySorting = () => {
let array = [37, 2, 89, 65, 1, 28, 41];
let index = 1;
let nextIndex = index + 1;
while (index < array.length) {
if (array[index - 1] < array[index]) {
index = nextIndex;
nextIndex++;
} else {
temp = array[index - 1];
array[index - 1] = array[index];
array[index] = temp;
index--;
if (index === 0) {
index = nextIndex;
nextIndex++;
}
}
}
return array;
}
console.log(arraySorting());
</pre>
<pre id="code-comb">
//Сортировка расчёской
const arraySorting = () => {
let array = [37, 2, 89, 65, 1, 28, 41];
const l = array.length;
const constant = 1.247;
let step = l / constant;
while (step > 1) {
const stepRound = Math.floor(step);
for (let i = 0, j = stepRound; j < l; i++, j++) {
if (array[i] > array[j]) {
[array[i], array[j]] = [array[j], array[i]];
}
}
step = stepRound / constant;
}
return array;
}
console.log(arraySorting());
</pre>
<pre id="code-selection">
//Сортировка выбором
const arraySorting = () => {
let array = [37, 2, 89, 65, 1, 28, 41];
const l = array.length;
for (let i = 0; i < l; i++) {
let min = i;
for (let j = i; j < l; j++) {
if (array[j] < array[min]) {
min = j;
}
}
if (min != i) {
let temp = array[i];
array[i] = array[min];
array[min] = temp;
}
}
return array;
}
console.log(arraySorting());
</pre><pre id="code-double-selection">
//Двухсторонняя сортировка выбором
const arraySorting = () => {
let array = [37, 2, 89, 65, 1, 28, 41];
const l = array.length;
for(i = 0, end = l-1; i < end; i++, end--){
let min = i;
let max = i;
for (let j = i; j <= end; j++) {
if (array[j] < array[min]) {
min = j;
}
if (array[j] > array[max]) {
max = j;
}
}
if (min !== i) {
let temp = array[i];
array[i] = array[min];
array[min] = temp;
if (max === i) {
max = min;
}
}
if (max !== end) {
let temp = array[end];
array[end] = array[max];
array[max] = temp;
}
}
return array;
}
console.log(arraySorting());
</pre>
<pre id="code-double-selection">
//Двухсторонняя сортировка выбором
const arraySorting = () => {
let array = [37, 2, 89, 65, 1, 28, 41];
const l = array.length;
for(i = 0, end = l-1; i < end; i++, end--){
let min = i;
let max = i;
for (let j = i; j <= end; j++) {
if (array[j] < array[min]) {
min = j;
}
if (array[j] > array[max]) {
max = j;
}
}
if (min !== i) {
let temp = array[i];
array[i] = array[min];
array[min] = temp;
if (max === i) {
max = min;
}
}
if (max !== end) {
let temp = array[end];
array[end] = array[max];
array[max] = temp;
}
}
return array;
}
console.log(arraySorting());
</pre>
</div>
<canvas id='sort-canvas'></canvas>
<p id="original-array"></p>
</div>
<a href="https://github.com/artengin/artengin.github.io" target="_blank" class="git-link"><img src="img/git.png" alt="GitHub.io"></a>
<script src="js/script.v.0.8.js"></script>
</body>
</html>