Skip to content

Commit e2f677f

Browse files
committed
Reestruturação da lógica do algoritimo
1 parent 6fd1a94 commit e2f677f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

Javascript/BuscaLinear.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
function buscaLinear(vetor, valorBuscado, inicio, fim){
2-
let posicao = -1;
3-
4-
if(inicio > fim){
5-
return posicao;
6-
}
7-
8-
for(let i = inicio; i < fim; i++){
1+
function buscaLinear(vetor, valorBuscado){
2+
for(let i = 0; i < vetor.length; i++){
93
if(vetor[i] == valorBuscado){
10-
posicao = i;
4+
return i;
115
}
126
}
13-
return posicao;
7+
return -1;
148
}
159

1610
var vetor = [54,42,11,33,24,99,77,80];
17-
console.log(buscaLinear(vetor, 11, 0, vetor.length));
11+
console.log(buscaLinear(vetor, 11));

0 commit comments

Comments
 (0)