Got the tests for binary search to compile, needs debugging (failing some assertions).
This commit is contained in:
parent
c179b2d67e
commit
8f04b93fae
|
@ -5,7 +5,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "binary_search.h"
|
||||
#include "../../utils/swap_void.h"
|
||||
#endif /* BINARY_SEARCH_C */
|
||||
|
||||
/* Note that if the comparison function is NULL, the array pointer is NULL or the search value is NULL, then the function will quit. */
|
||||
|
@ -30,9 +29,9 @@ int binary_search(void *array, void *value, int (*comparison_function)(const voi
|
|||
/* Calculate the current index. */
|
||||
current_index = (index_left + index_right) / 2;
|
||||
/* Check where the index is in the array in comparison to the value we're looking for. */
|
||||
if (comparison_function(array + current_index, value) == BINARY_SEARCH_INDEX_LESS_THAN)
|
||||
if (comparison_function(array + current_index, value) == BINARY_SEARCH_COMPARISON_LESS_THAN)
|
||||
index_left = current_index + 1;
|
||||
else if (comparison_function(array + current_index, value) == BINARY_SEARCH_INDEX_LARGER_THAN)
|
||||
else if (comparison_function(array + current_index, value) == BINARY_SEARCH_COMPARISON_LARGER_THAN)
|
||||
index_right = current_index - 1;
|
||||
else
|
||||
return current_index;
|
||||
|
|
|
@ -38,11 +38,11 @@ stack_tests.out: stack_tests.c
|
|||
tree_tests.out: tree_tests.c
|
||||
gcc -g -fsanitize=address -fsanitize=leak -fsanitize=undefined tree_tests.c -o tree_tests.out
|
||||
|
||||
binary_search.o: ../misc_algorithms/search/binary_search.c ../misc_algorithms/search/binary_search.h swap_void.o
|
||||
gcc -g -I ../../utils -fsanitize=address -fsanitize=leak -fsanitize=undefined ../misc_algorithms/search/binary_search.c -o binary_search.o
|
||||
binary_search.o: ../misc_algorithms/search/binary_search.c ../misc_algorithms/search/binary_search.h
|
||||
gcc -g -I ../misc_algorithms/search/ -c ../misc_algorithms/search/binary_search.c -o binary_search.o
|
||||
|
||||
binary_search_tests.o: binary_search_tests.c
|
||||
gcc -g -I ../misc_algorithms/binary_search/ -D DEBUG -c binary_search_tests.c -o binary_search_tests.o
|
||||
gcc -g -I ../misc_algorithms/binary_search/ -c binary_search_tests.c -o binary_search_tests.o
|
||||
|
||||
binary_search_tests.out: binary_search_tests.o binary_search.o
|
||||
gcc -g -fsanitize=address -fsanitize=leak -fsanitize=undefined binary_search.o binary_search_tests.o -o binary_search_tests.out
|
||||
|
|
Loading…
Reference in New Issue