/** * test1.c - A very simple test of a binary search algorithm - build * an array and look at some values. */ #include "bs.h" #include #include void report (int value, int values[], int count) { printf ("The position of %d is %d.\n", value, binary_search (value, values, count)); } // report int main () { int values[] = { -5, 2, 8, 12 }; int count = 4; int i; printf ("Values: "); for (i = 0; i < count; i++) printf ("%4d", values[i]); printf ("\n"); printf ("Indices: "); for (i = 0; i < count; i++) printf ("%4d", i); printf ("\n"); // Check values in the array report (-5, values, count); report (2, values, count); report (8, values, count); report (12, values, count); // Check values outside the extrema report (-10, values, count); report (100, values, count); // Check values in the middle report (3, values, count); report (4, values, count); report (9, values, count); // And we're done return EXIT_SUCCESS; } // main ()