diff options
author | Michael Hunteman <michael@huntm.net> | 2023-07-04 17:03:53 -0500 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2023-07-06 17:23:45 -0500 |
commit | bfce8f0d0d828209ec0bec71371ee94a7ad62d3e (patch) | |
tree | bdf49ca788ca1ca030d5b1cccfd0c9dffeb3f69f /three/search.c |
Initial commit
Diffstat (limited to 'three/search.c')
-rw-r--r-- | three/search.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/three/search.c b/three/search.c new file mode 100644 index 0000000..30426c7 --- /dev/null +++ b/three/search.c @@ -0,0 +1,25 @@ +#include <stdio.h> + +int +binsearch(int x, int v[], int n) +{ + int low, high, mid; + low = 0; + high = n - 1; + while (low <= high) { + mid = (low + high) / 2; + if (x < v[mid]) { + high = mid - 1; + } else { + low = mid; + } + } + return -1; +} + +int +main() +{ + binsearch(); + return 0; +} |