Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. public class BinarySearch {
  2. public boolean search(int array[], int key, int lo, int hi) {
  3.  
  4.  
  5. if (array.length == 0){
  6. System.out.println("The array is empty");
  7. return false;
  8. }
  9.  
  10. do {
  11. int place = (lo + (hi - l)) / 2;
  12.  
  13. if (key == array[place]) {
  14. return true;
  15. }
  16. if (array[place] < key)
  17. lo = place + 1;
  18. else
  19. hi = place - 1;
  20. } while (lo <= hi)
  21.  
  22. return false;
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement