diff --git a/docs/generate_docs.sh b/docs/generate_docs.sh index 862dc8d..8a3910c 100755 --- a/docs/generate_docs.sh +++ b/docs/generate_docs.sh @@ -5,7 +5,7 @@ # Prompt user at the start for what type they want. # Specify the file paths, in the order where they should be built. -filepaths=('nodes/single_node.h.ms' 'nodes/double_node.h.ms' 'nodes/tree_node.h.ms' 'strings/strzcpy.ms' 'stack/stack.h.ms' 'linked_lists/double_linked_list.h.ms' 'linked_lists/single_linked_list.h.ms' 'utils/time_function.h.ms' 'trees/binary_tree/binary_tree.h.ms') +filepaths=('nodes/single_node.h.ms' 'nodes/double_node.h.ms' 'nodes/tree_node.h.ms' 'strings/strzcpy.ms' 'stack/stack.h.ms' 'linked_lists/double_linked_list.h.ms' 'linked_lists/single_linked_list.h.ms' 'utils/time_function.h.ms' 'trees/binary_tree/binary_tree.h.ms' 'misc_algorithms/search/binary_search.h.ms') # Prompt the user for the option they want (pdf/html/utf8). echo "Please choose an output option: pdf, html or utf8." diff --git a/docs/misc_algorithms/search/binary_search.h.ms b/docs/misc_algorithms/search/binary_search.h.ms new file mode 100644 index 0000000..469632d --- /dev/null +++ b/docs/misc_algorithms/search/binary_search.h.ms @@ -0,0 +1,41 @@ +.DA + +.TL +binary_search.h + +.AU +Wael Karram + +.AB no +Documentation for binary_search.h +.AE + +.AD + +.LP +This header defines a generic binary search function. Using the prepoccessor variable BINARY_SEARCH_H used as an include guard. + +.LP +These are the compile-time constants declared by this header: +.br +BINARY_SEARCH_COMPARISON_LARGER_THAN, returned by the comparison function when the result is \[char34]larger than\[char34], evaluates to 1. +.br +BINARY_SEARCH_COMPARISON_LESS_THAN, returned by the comparison function when the result is \[char34]less than\[char34], evaluates to -1. +.br +BINARY_SEARCH_INDEX_NOT_FOUND, returned when the value isn't found, evaluated to -1. + + +.LP +These are the function defitions and input arguments for this file. +.br +.I "int binary_search(void *array, void *value, int (*comparison_function)(const void*, const void*), const int length, size_t size);" +.br +.I "void *array" " is the array to search in - if NULL the function will quit." +.br +.I "void *value" " is the value to look for - if NULL the function will quit." +.br +.I "int (*comparison_function)(const void*, const void*)" " is the comparison function used, if larger than returns 1, if less than returns -1, otherwise returns 0. If NULL - the function will exhibit undefined behavior." +.br +.I "const int length" " is the length of the array, must be positive." +.br +.I "size_t size" " is the size of a single object/element in the array, must be positive." diff --git a/misc_algorithms/search/binary_search.c b/misc_algorithms/search/binary_search.c index ef8c5d3..8505841 100644 --- a/misc_algorithms/search/binary_search.c +++ b/misc_algorithms/search/binary_search.c @@ -13,7 +13,7 @@ /* The array's length should be passed in the length argument. */ /* Size should match a single object's size, and should be > 0. */ /* The function returns BINARY_SEARCH_INDEX_NOT_FOUND on error or not found, otherwise will return the index of the value. */ -int binary_search(void* array, void *value, int (*comparison_function)(const void*, const void*), const int length, size_t size) { +int binary_search(void *array, void *value, int (*comparison_function)(const void*, const void*), const int length, size_t size) { /* Local variables. */ int index_left, index_right, current_index; diff --git a/progress_and_notes b/progress_and_notes index 14888dc..3a5583e 100644 --- a/progress_and_notes +++ b/progress_and_notes @@ -40,10 +40,10 @@ Binary Search (in a sorted array). To be implemented: Merge Sort. Introspective sort (Uses both quicksort and merge sort). +Heap. Heapsort (after implementing heaps). Insertion sort. Hashmap. -Heap. AVL trees. Red-Black trees. AA Trees (?). @@ -52,3 +52,4 @@ Array list (?). Dynamic array/vector. Misc tasks: +None!