Advertisement
GrandtherAzaMarks

BinSearch

Apr 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. static bool BinSearch(ref long[] N, long key)
  2.         {
  3.             long l = -1, r = N.Length, m = 0;
  4.             while (l < r - 1)
  5.             {
  6.                 m = (l + r) / 2;
  7.                 if (N[m] < key)
  8.                     l = m;
  9.                 else
  10.                     r = m;
  11.             }
  12.  
  13.             if (r == N.Length)
  14.                 return false;
  15.             else if (N[r] == key)
  16.             {
  17.                 N[r] = -1;
  18.                 return true;
  19.             }
  20.             else
  21.                 return false;
  22.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement