|
|
@ -1,7 +1,7 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Write a recursive function that searches for a target in a sorted array using
|
|
|
|
Write a recursive function that searches for a target in a sorted array using
|
|
|
|
binay search, where the array, its size and the target are given as parameters.
|
|
|
|
binay search, where the array, its size and the target are given as parameters.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
@ -9,7 +9,7 @@ binay search, where the array, its size and the target are given as parameters.
|
|
|
|
|
|
|
|
|
|
|
|
#define DEBUG 1
|
|
|
|
#define DEBUG 1
|
|
|
|
#define debug_printf(fmt, ...) \
|
|
|
|
#define debug_printf(fmt, ...) \
|
|
|
|
do { if (DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
|
|
|
|
do { if (DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
|
|
|
|
|
|
|
|
|
|
|
|
void assert_sorted(int array[], int arraylen) {
|
|
|
|
void assert_sorted(int array[], int arraylen) {
|
|
|
|
int n = INT_MIN;
|
|
|
|
int n = INT_MIN;
|
|
|
@ -51,7 +51,8 @@ int main(void) {
|
|
|
|
21090, 22277, 22624, 24634, 24877,
|
|
|
|
21090, 22277, 22624, 24634, 24877,
|
|
|
|
25367, 25586, 26706, 26720, 26958,
|
|
|
|
25367, 25586, 26706, 26720, 26958,
|
|
|
|
27478, 28269, 29142, 30630, 30804,
|
|
|
|
27478, 28269, 29142, 30630, 30804,
|
|
|
|
31984, 32398, 32588 };
|
|
|
|
31984, 32398, 32588
|
|
|
|
|
|
|
|
};
|
|
|
|
assert_sorted(a, 43);
|
|
|
|
assert_sorted(a, 43);
|
|
|
|
|
|
|
|
|
|
|
|
assert(binsearch(a, 43, 912) == 0);
|
|
|
|
assert(binsearch(a, 43, 912) == 0);
|
|
|
|