From 65cf641e9533b190db870d0cc46f2f852239ebf6 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 4 Apr 2020 23:36:19 +0200 Subject: Added test for ft_strsjoin, ft_strsjoinf, ft_vecpush_safe, Added doc for algo functions, tested functions --- src/algo/ft_mergesort.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/algo/ft_mergesort.c') diff --git a/src/algo/ft_mergesort.c b/src/algo/ft_mergesort.c index 25b4255..8556145 100644 --- a/src/algo/ft_mergesort.c +++ b/src/algo/ft_mergesort.c @@ -6,12 +6,19 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/10 02:26:41 by cacharle #+# #+# */ -/* Updated: 2020/02/13 23:14:21 by cacharle ### ########.fr */ +/* Updated: 2020/04/04 22:40:55 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft_algo.h" +/* +** \brief Helper function to return in case of error +** \param left Left subarray +** \param right Right subarray +** \return -1 to indicate error +*/ + static int st_mergesort_error(void *left, void *right) { free(left); @@ -19,6 +26,13 @@ static int st_mergesort_error(void *left, void *right) return (-1); } +/* +** \brief Merge 2 sorted arrays +** \param arrays Struct containing the arrays (base, left, right) +** \param nel Number of element in base +** \param compar Comparison function +*/ + static void st_merge_sorted(struct s_merge_sorted_arrays *arrays, size_t nel, size_t width, int (*compar)(const void *, const void *)) { @@ -49,6 +63,14 @@ static void st_merge_sorted(struct s_merge_sorted_arrays *arrays, size_t nel, arrays->right + ri++ * width, width); } +/* +** \brief Sort an array using the merge sort algorithm +** \param base Array to sort +** \param nel Number of element in the array +** \param width Size of each element +** \return 0 on success, -1 on error +*/ + int ft_mergesort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *)) { -- cgit