Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- bool b_search(int value, int values[], int n);
- int main (void)
- {
- int nums[] = {1, 2, 3, 234, 22, 52, 12};
- if(b_search(22, nums, 7))
- printf("HEllo yes\n");
- printf("test\n");
- return 0;
- }
- #include <stdbool.h>
- bool binary_search(int value, int values[], int n)
- {
- int beginning = 0;
- int ending = n-1;
- while ( ending > beginning )
- {
- int middle = (beginning + ending) / 2;
- if (values[middle] == value)
- {
- return true;
- }
- else if (values[middle] > value)
- {
- ending = values[middle - 1];
- }
- else
- {
- beginning = middle + 1;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment