Guest User

Untitled

a guest
Jun 23rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. public int IndexOf (int el) {
  2.        
  3.         // Copy the elements array
  4.         int[] tmp = elements;
  5.        
  6.         while (true) {
  7.            
  8.             int middleIndex = (int)Math.floor(tmp.length/2);
  9.             int value = tmp[middleIndex];
  10.            
  11.             if (el < value) {
  12.                 // Element is in the lower half
  13.                
  14.                 tmp = elements[0 - middleIndex];
  15.                
  16.             } else if (el > value){
  17.                 // Element is in the upper half
  18.                
  19.                
  20.                
  21.             } else {
  22.                 // Element is equal to the middle value
  23.                 return middleIndex;
  24.             }
  25.            
  26.            
  27.         }
  28.        
  29.        
  30.     }
Add Comment
Please, Sign In to add comment