Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int IndexOf (int el) {
- // Copy the elements array
- int[] tmp = elements;
- while (true) {
- int middleIndex = (int)Math.floor(tmp.length/2);
- int value = tmp[middleIndex];
- if (el < value) {
- // Element is in the lower half
- tmp = elements[0 - middleIndex];
- } else if (el > value){
- // Element is in the upper half
- } else {
- // Element is equal to the middle value
- return middleIndex;
- }
- }
- }
Add Comment
Please, Sign In to add comment