1
0
Fork 0

Update documentation and add docs for binary search.

This commit is contained in:
wael 2021-11-10 12:03:47 +02:00
parent acbef5d0ec
commit 9de0cd367d
4 changed files with 45 additions and 3 deletions

View File

@ -5,7 +5,7 @@
# Prompt user at the start for what type they want. # Prompt user at the start for what type they want.
# Specify the file paths, in the order where they should be built. # 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). # Prompt the user for the option they want (pdf/html/utf8).
echo "Please choose an output option: pdf, html or utf8." echo "Please choose an output option: pdf, html or utf8."

View File

@ -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."

View File

@ -13,7 +13,7 @@
/* The array's length should be passed in the length argument. */ /* The array's length should be passed in the length argument. */
/* Size should match a single object's size, and should be > 0. */ /* 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. */ /* 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. */ /* Local variables. */
int index_left, index_right, current_index; int index_left, index_right, current_index;

View File

@ -40,10 +40,10 @@ Binary Search (in a sorted array).
To be implemented: To be implemented:
Merge Sort. Merge Sort.
Introspective sort (Uses both quicksort and merge sort). Introspective sort (Uses both quicksort and merge sort).
Heap.
Heapsort (after implementing heaps). Heapsort (after implementing heaps).
Insertion sort. Insertion sort.
Hashmap. Hashmap.
Heap.
AVL trees. AVL trees.
Red-Black trees. Red-Black trees.
AA Trees (?). AA Trees (?).
@ -52,3 +52,4 @@ Array list (?).
Dynamic array/vector. Dynamic array/vector.
Misc tasks: Misc tasks:
None!