Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int bsearch(Item idToSearch, int first, int last)
- {
- int mid = (first + last)/2;
- int a = 0;
- if(last <= first)
- a = -1;
- //id is below midpoint
- else if(idToSearch.compareTo(myStore[mid]) < 0)
- {
- return bsearch(idToSearch, first, mid);
- }
- //id is above the midpoint
- else if(idToSearch.compareTo(myStore[mid]) > 0)
- {
- return bsearch(idToSearch, mid+1, last-1);
- }
- //id is the midpoint
- else
- {
- a = mid;
- }
- return a;
- /**
- * int mid = myStore.length/2;
- * if(idToSearch.getId >myStore[mid].getId)
- * {
- *
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement