Giter Club home page Giter Club logo

Comments (1)

ricardocarva avatar ricardocarva commented on May 18, 2024 1

Hi @vinicius-developer. I am not sure if you have fixed this issue as or not as this PR has been opened for quite a while.

I ran the following code in a Java Playground, and I didn't experience any exceptions.

`public class BuscaBinaria
{
public int posicao;

BuscaBinaria(int[] array, int objetivo) {
this.posicao = BinarySearch(objetivo, array);
}

public int GetResultado() {
return this.posicao;
}

public int BinarySearch(int objetivo, int[] array) {
int comeco = 0;
int fim = array.length - 1;

while (comeco <= fim) {
  int meio = comeco + (fim - comeco) / 2;
  if (array[meio] == objetivo) return meio;
  if (array[meio] < objetivo) comeco = meio + 1;
  else fim = meio - 1;
}
return -1;

}

public static void main(String[] args) {
int[] array = {1, 3, 5, 7, 9, 11};
int objetivo = 15;
BuscaBinaria busca = new BuscaBinaria(array, objetivo);

int resultado = busca.GetResultado();
System.out.println("O índice do elemento " + objetivo + " é: " + resultado);

}
}
`

I did find a PR (#136) from you fixing this bug in the python algorithm.

As there was no further information on how to reproduce this issue and the PR is about 2 years old, I am closing this PR.

Should the issue be still present, please raise a new issue with more details.

Thank you!

from algorithms-and-data-structures.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.