Advertisement
Guest User

Untitled

a guest
May 6th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. int search(List first,int key, int low, int high){
  2.     int pivot;
  3.     if(low <= high){
  4.         pivot = (low + high) / 2;
  5.         first.moveCursor(pivot);
  6.         if(first.getCursor() == key){
  7.             return pivot;
  8.         }else if(key < first.getCursor()){
  9.             return search(first, key, low, pivot-1);
  10.         }else if(key > first.getCursor()){
  11.             return search(first, key, pivot+1, high);
  12.         }
  13.     }
  14.     else{
  15.         return -1;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement