Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BinarySearch {
- public boolean search(int array[], int key, int lo, int hi) {
- if (array.length == 0){
- System.out.println("The array is empty");
- return false;
- }
- do {
- int place = (lo + (hi - l)) / 2;
- if (key == array[place]) {
- return true;
- }
- if (array[place] < key)
- lo = place + 1;
- else
- hi = place - 1;
- } while (lo <= hi)
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement