From bfce8f0d0d828209ec0bec71371ee94a7ad62d3e Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Tue, 4 Jul 2023 17:03:53 -0500 Subject: Initial commit --- three/search.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 three/search.c (limited to 'three/search.c') 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 + +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; +} -- cgit v1.2.3