diff --git a/sorting_algorithms/quicksort/quicksort.c b/sorting_algorithms/quicksort/quicksort.c index 8746ee9..bf51b60 100644 --- a/sorting_algorithms/quicksort/quicksort.c +++ b/sorting_algorithms/quicksort/quicksort.c @@ -2,41 +2,24 @@ /* Include guards + include statements. */ #ifndef QUCIK_SORT_C #define QUICK_SORT_C -#include #include "quicksort.h" #endif /* QUICK_SORT_C */ /* Function implementations. */ -/* This is the standard (<) comparison function. */ -int standard_compare_quick_sort(const void* first, const void* second) { - /* Sanity check. */ - if (first == NULL && second != NULL) - return 1; - else if (first != NULL && second == NULL) - return 0; - else if (first == NULL && second == NULL) - return 0; - else - return *((int*)first) <= *((int*)second); /* THIS IS WRONG AND SHOULD BE FIXED! */ -} - -/* Note that if the comparison function is NULL, then the regular comparison operator is used <. */ +/* Note that if the comparison function is NULL, then the function will quit! */ /* Note that the comparison function should return 1 if the second argument is larger than or * equal to the first, otherwise zero. */ /* The array's length should be passed in the length argument. */ /* The function returns a NULL pointer on error, caller must check! */ void* quick_sort(void* array, int (*comparison_function)(const void*, const void*), const size_t length, const size_t size) { /* Sanity check. */ - if (array == NULL) + if (array == NULL || comparison_function == NULL) return NULL; /* Rely on the standard qsort library function. */ /* Sort according to ptr, and based on the employed comparison function. */ - if (comparison_function != NULL) - qsort(array, length, size, standard_compare_quick_sort); - else - qsort(array, length, size, comparison_function); + qsort(array, length, size, comparison_function); /* Return the result. */ return array; diff --git a/sorting_algorithms/quicksort/quicksort.h b/sorting_algorithms/quicksort/quicksort.h index 990505c..fcafacc 100644 --- a/sorting_algorithms/quicksort/quicksort.h +++ b/sorting_algorithms/quicksort/quicksort.h @@ -1,9 +1,7 @@ /* This header defines the function for quick sort. */ #ifndef QUICK_SORT_H #define QUICK_SORT_H -#include -/* This is the standard (<) comparison function. */ -int standard_compare_quick_sort(const void* first, const void* second); + /* The quicksort function's definition. */ void* quick_sort(void* array, int (*comparison_function)(const void*, const void*), const size_t length, const size_t size); #endif /* QUICK_SORT_H */