daily pastebin goal
41%
SHARE
TWEET

Binsearch

keverman Feb 12th, 2018 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool binSearch(std::vector<int> T, int key)
  2. {
  3.     int lhs = 0, rhs = T.size() - 1;
  4.  
  5.     while (lhs <= rhs)
  6.     {
  7.         int mid = lhs + (rhs - lhs) / 2;
  8.  
  9.         if (key == T[mid]) return true;
  10.         if (key < T[mid])  rhs = mid - 1;
  11.         else               lhs = mid + 1;
  12.     }
  13.  
  14.     return false;
  15. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top