Created
October 14, 2012 21:00
-
-
Save nitschmann/3889806 to your computer and use it in GitHub Desktop.
Methode zur binären Suche in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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