Advertisement
STANAANDREY

CircularSortedArrSrc

Jul 29th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. bool CircularSortedArrSrc(int v[], int n, int x)
  2. {
  3.     int st = 0, dr = n - 1,mid;
  4.     while (st <= dr)
  5.     {
  6.         mid = (st + dr)/2;
  7.         if (v[mid] == x)
  8.             return true;
  9.         if (v[mid] <= v[dr])
  10.         {
  11.             if (x > v[mid] && x <= v[dr])
  12.                 st = mid + 1;
  13.             else
  14.                 dr = mid - 1;
  15.         }
  16.         else
  17.         {
  18.             if (v[st] <= x && x < v[mid])
  19.                 dr = mid - 1;
  20.             else
  21.                 st = mid + 1;
  22.         }
  23.     }
  24.     return false;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement