Skip to content

Commit a6293a5

Browse files
Juliana TagamiJuliana Tagami
Juliana Tagami
authored and
Juliana Tagami
committed
git
0 parents  commit a6293a5

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

bolha.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var valores = [8, 7, 6, 5, 4, 3, 2, 1];
2+
3+
function ordena() {
4+
let inicio = 0;
5+
let fim = 8;
6+
let tmp;
7+
8+
for (vezes = 0; vezes < 8; vezes++) {
9+
for (pos = inicio; pos < fim -1; pos++) {
10+
if (valores[pos] > valores[pos + 1]) {
11+
tmp = valores[pos];
12+
valores[pos] = valores[pos + 1];
13+
valores[pos + 1] = tmp;
14+
}
15+
}
16+
}
17+
}
18+
19+
ordena();
20+
console.log("Vetor ordenado...");
21+
console.log(valores);

busca.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var valores = [10, 20, 45, 90, 50];
2+
3+
function busca(num) {
4+
for (i=0; i < 6; i++) {
5+
if (num == valores[i]) {
6+
return i;
7+
}
8+
}
9+
return -1;
10+
}
11+
12+
function buscaBin(num) {
13+
let inicio, fim;
14+
let meio;
15+
let passos = 0;
16+
inicio = 0;
17+
fim = 9;
18+
while (inicio <= fim) {
19+
meio = parseInt((inicio + fim) / 2);
20+
passos = passos + 1;
21+
if (num == valores[meio]) {
22+
console.log("achei em" + passos + "passos");
23+
return meio;
24+
} else {
25+
if (num > valores[meio]) {
26+
inicio = meio + 1;
27+
} else {
28+
fim = meio - 1;
29+
}
30+
}
31+
}
32+
console.log("não achei " + passos + "passos");
33+
return -1;
34+
}
35+
36+
console.log(buscaBin(10));
37+
console.log(buscaBin(50));
38+
console.log(buscaBin(200));

pilha.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var elements = [];
2+
var topo = -1;
3+
const MAX =10;
4+
5+
function push(num){
6+
if (topo < MAX){
7+
topo = topo + 1;
8+
elements[topo] = num;
9+
}
10+
else{
11+
console.log("Pilha esta cheia");
12+
}
13+
}
14+
15+
function estaVazia(){
16+
return topo == -1;
17+
}
18+
19+
20+
function pop(){
21+
if (topo!= -1){
22+
let num = elements[topo];
23+
topo = topo -1;
24+
return num;
25+
}
26+
else{
27+
console.log("Pilha esta vazia");
28+
}
29+
}
30+
31+
32+
33+
push(10);
34+
push(20);
35+
push(30);
36+
37+
console.log(elements);
38+
39+
console.log(pop());
40+
console.log(pop());
41+
console.log(pop());

0 commit comments

Comments
 (0)