Advertisement
ahmed19981973

Untitled

Feb 6th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.64 KB | None | 0 0
  1.  public static<T extends Comparable<T>> int Binary2Search (T key,List pl){
  2.                   return search(key,pl,0,pl.listSize()-1);
  3.     }
  4.  
  5.     public static<T extends Comparable<T>> int search (T key,List<T> pl,int bottom,int top ){
  6.         int  middle ;
  7.         if (top>=bottom){
  8.             middle=  (top+bottom)/2;
  9.             if (key==(pl.retreiveList(middle)))
  10.                 return middle;
  11.             if (key.compareTo(pl.retreiveList(middle))<0){
  12.                 return  search(key,pl,bottom,middle-1);
  13.             }
  14.             else
  15.                 return search(key, pl, middle + 1, top) ;
  16.  
  17.         }
  18.         return -1;
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement