Skip to content

Instantly share code, notes, and snippets.

@nitschmann
Created October 14, 2012 21:00
Show Gist options
  • Save nitschmann/3889806 to your computer and use it in GitHub Desktop.
Save nitschmann/3889806 to your computer and use it in GitHub Desktop.
Methode zur binären Suche in Java
public static int binaereSuche(int[] feld, int x)
{
int unten=0, mitte=0, oben=feld.length;
while (unten<oben)
{
mitte=(unten+oben)/2;
if (feld[mitte]==x)
{
return mitte+1;
}
if (feld[mitte]>x)
{
oben=mitte;
}
else
{
unten=mitte+1;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment