-
Notifications
You must be signed in to change notification settings - Fork 0
/
ordenando.html
68 lines (61 loc) · 2.08 KB
/
ordenando.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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordenando</title>
</head>
<body>
<label for="valor">Valor:</label>
<input type="number" id="valor">
<button onclick="add()">Adicionar</button>
<br><br>
<label for="algoritmo">Escolha um algoritmo de ordenação:</label>
<select id="algoritmo">
<option value="bubble">Bubble Sort</option>
<option value="selection">Selection Sort</option>
<option value="quick" selected>Quick Sort</option>
</select>
<button onclick="ordenar()">Ordenar</button>
<button onclick="misturar()">Misturar</button>
<ul id="valores"></ul>
<!-- Incluindo o arquivo "ordenando.js" -->
<script src="exemplosjs/ordenando.js"></script>
<!-- Chamada das funções -->
<script>
// Função add
function add() {
const valor = document.getElementById('valor').value;
const valores = document.getElementById('valores');
const node = document.createElement('li');
const textNode = document.createTextNode(valor);
node.appendChild(textNode);
valores.appendChild(node);
}
// Função ordenar
function ordenar() {
const valores = document.getElementById('valores').children;
const vetor = Array.from(valores).map(item => parseInt(item.innerHTML));
const algoritmo = document.getElementById('algoritmo').value;
switch (algoritmo) {
case 'bubble':
bubble_sort(vetor);
break;
case 'selection':
selection_sort(vetor);
break;
case 'quick':
quick_sort(vetor);
break;
}
document.getElementById('valores').innerHTML = vetor.map(item => `<li>${item}</li>`).join('');
}
// Função misturar
function misturar() {
const valores = Array.from(document.getElementById('valores').children).map(item => parseInt(item.innerHTML));
shuffle(valores);
document.getElementById('valores').innerHTML = valores.map(item => `<li>${item}</li>`).join('');
}
</script>
</body>
</html>