Advertisement
skilletwaffles

lab 28.1

Mar 10th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public int bsearch(Item idToSearch, int first, int last)
  2. {
  3. int mid = (first + last)/2;
  4. int a = 0;
  5. if(last <= first)
  6. a = -1;
  7.  
  8. //id is below midpoint
  9. else if(idToSearch.compareTo(myStore[mid]) < 0)
  10. {
  11. return bsearch(idToSearch, first, mid);
  12. }
  13.  
  14. //id is above the midpoint
  15. else if(idToSearch.compareTo(myStore[mid]) > 0)
  16. {
  17. return bsearch(idToSearch, mid+1, last-1);
  18. }
  19.  
  20. //id is the midpoint
  21. else
  22. {
  23. a = mid;
  24. }
  25.  
  26. return a;
  27.  
  28. /**
  29. * int mid = myStore.length/2;
  30. * if(idToSearch.getId >myStore[mid].getId)
  31. * {
  32. *
  33. */
  34.  
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement