Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Método faz a pesquisa binária
- public static int pesquisaBinaria(int x) {
- int esq = 0;
- int dir = vetor.length - 1;
- int meio;
- do {
- meio = esq + (dir - esq) / 2;
- if (x < vetor[meio]) {
- dir = meio - 1;
- } else if (x > vetor[meio]) {
- esq = meio + 1;
- } else {
- return 1;
- }
- } while (esq <= dir);
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment