Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //thuat toan tim kiem nhi phan
- int Binary(int* a, int n, int x)
- {
- int left = 0;
- int right = n-1;
- int mid;
- while ( left <= right)
- {
- mid =( left + right ) / 2;
- if ( x < a[mid] )
- right = mid - 1;
- else if ( x > a[mid] )
- left = mid + 1;
- else
- return mid;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement