From 8131a5d26441c5152ab151b4bb49b561e5ca6e81 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 31 Jan 2020 10:44:30 +0100 Subject: hash table unit testing, norming --- src/lst/ft_lstbsearch.c | 2 +- src/lst/ft_lstpop_front.c | 4 ++-- src/lst/ft_lstremove_if.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/lst') diff --git a/src/lst/ft_lstbsearch.c b/src/lst/ft_lstbsearch.c index d694209..d3dc7e4 100644 --- a/src/lst/ft_lstbsearch.c +++ b/src/lst/ft_lstbsearch.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:17:51 by cacharle #+# #+# */ -/* Updated: 2020/02/17 03:03:21 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:12:12 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c index ff386f9..5bf2c60 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/25 03:32:51 by cacharle #+# #+# */ -/* Updated: 2020/01/15 12:46:28 by cacharle ### ########.fr */ +/* Created: 2020/01/30 08:29:58 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:12:47 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index 5221ae4..03643fa 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:36:49 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:06:22 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:20:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -- cgit From 915f1b888cf9c05e4b61321f84ac045eacd8ddd1 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 27 Feb 2020 18:07:57 +0100 Subject: Added ft_lstlfind,ft_lstlsearch and ft_split_destroy --- src/lst/ft_lstlfind.c | 4 ++-- src/lst/ft_lstlsearch.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/lst') diff --git a/src/lst/ft_lstlfind.c b/src/lst/ft_lstlfind.c index 92d37d8..c399b6e 100644 --- a/src/lst/ft_lstlfind.c +++ b/src/lst/ft_lstlfind.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/17 03:04:52 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:03:11 by cacharle ### ########.fr */ +/* Created: 2020/02/27 18:00:37 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:24:05 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstlsearch.c b/src/lst/ft_lstlsearch.c index 8d2acc8..f59b5de 100644 --- a/src/lst/ft_lstlsearch.c +++ b/src/lst/ft_lstlsearch.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/17 02:57:12 by cacharle #+# #+# */ -/* Updated: 2020/02/17 03:35:45 by cacharle ### ########.fr */ +/* Created: 2020/02/27 16:18:33 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:24:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -- cgit From 901402c99018422c994bdb297e3ba404969c88ea Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 30 Mar 2020 22:26:36 +0200 Subject: Added documentation for ht and lst --- src/lst/ft_lstadd_back.c | 26 -------------------------- src/lst/ft_lstadd_front.c | 22 ---------------------- src/lst/ft_lstbsearch.c | 4 ++-- src/lst/ft_lstclear.c | 25 ------------------------- src/lst/ft_lstdelone.c | 10 +++++++--- src/lst/ft_lstdestroy.c | 29 +++++++++++++++++++++++++++++ src/lst/ft_lstiter.c | 10 +++++++--- src/lst/ft_lstlast.c | 8 ++++++-- src/lst/ft_lstlfind.c | 2 +- src/lst/ft_lstlsearch.c | 2 +- src/lst/ft_lstmap.c | 21 ++++++++++++++------- src/lst/ft_lstnew.c | 12 ++++++++---- src/lst/ft_lstpop_front.c | 6 +++++- src/lst/ft_lstpush_back.c | 30 ++++++++++++++++++++++++++++++ src/lst/ft_lstpush_front.c | 26 ++++++++++++++++++++++++++ src/lst/ft_lstremove_if.c | 10 ++++++++-- src/lst/ft_lstreverse.c | 5 ++++- src/lst/ft_lstreverse_ret.c | 6 +++++- src/lst/ft_lstsize.c | 8 ++++++-- src/lst/ft_lstsort.c | 6 ++++++ src/lst/ft_lstsorted_merge.c | 10 +++++++++- 21 files changed, 174 insertions(+), 104 deletions(-) delete mode 100644 src/lst/ft_lstadd_back.c delete mode 100644 src/lst/ft_lstadd_front.c delete mode 100644 src/lst/ft_lstclear.c create mode 100644 src/lst/ft_lstdestroy.c create mode 100644 src/lst/ft_lstpush_back.c create mode 100644 src/lst/ft_lstpush_front.c (limited to 'src/lst') diff --git a/src/lst/ft_lstadd_back.c b/src/lst/ft_lstadd_back.c deleted file mode 100644 index 8f39a75..0000000 --- a/src/lst/ft_lstadd_back.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_back_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/09 09:02:03 by cacharle #+# #+# */ -/* Updated: 2019/11/20 04:01:26 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_lst.h" - -void ft_lstadd_back(t_ftlst **alst, t_ftlst *new) -{ - if (alst == NULL) - return ; - if (*alst == NULL) - { - *alst = new; - return ; - } - ft_lstlast(*alst)->next = new; -} diff --git a/src/lst/ft_lstadd_front.c b/src/lst/ft_lstadd_front.c deleted file mode 100644 index bcd5ad9..0000000 --- a/src/lst/ft_lstadd_front.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_front_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/09 09:02:25 by cacharle #+# #+# */ -/* Updated: 2019/10/18 12:16:06 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_lst.h" - -void ft_lstadd_front(t_ftlst **alst, t_ftlst *new) -{ - if (alst == NULL || new == NULL) - return ; - new->next = *alst; - *alst = new; -} diff --git a/src/lst/ft_lstbsearch.c b/src/lst/ft_lstbsearch.c index d3dc7e4..0c48eb0 100644 --- a/src/lst/ft_lstbsearch.c +++ b/src/lst/ft_lstbsearch.c @@ -46,11 +46,11 @@ static t_ftlst *st_lstbsearch_rec(t_ftlst *lst, t_ftlst *last, return (NULL); if (mid->next == NULL) { - if (cmp(ref, mid->content) == 0) + if (cmp(ref, mid->data) == 0) return (mid); return (NULL); } - res = cmp(ref, mid->next->content); + res = cmp(ref, mid->next->data); if (res < 0) return (st_lstbsearch_rec(lst, mid, cmp, ref)); else if (res > 0) diff --git a/src/lst/ft_lstclear.c b/src/lst/ft_lstclear.c deleted file mode 100644 index 0bacb4f..0000000 --- a/src/lst/ft_lstclear.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstclear_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/09 09:02:39 by cacharle #+# #+# */ -/* Updated: 2019/11/20 04:02:37 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_lst.h" - -void ft_lstclear(t_ftlst **lst, void (*del)(void *)) -{ - if (lst == NULL) - return ; - if (*lst == NULL) - return ; - ft_lstclear(&((*lst)->next), del); - ft_lstdelone(*lst, del); - *lst = NULL; -} diff --git a/src/lst/ft_lstdelone.c b/src/lst/ft_lstdelone.c index 63dcc35..40e25cd 100644 --- a/src/lst/ft_lstdelone.c +++ b/src/lst/ft_lstdelone.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstdelone_bonus.c :+: :+: :+: */ +/* ft_lstdelone.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,14 +10,18 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Delete list node +** \param del Delete function for node's data +*/ + void ft_lstdelone(t_ftlst *lst, void (*del)(void *)) { if (lst == NULL) return ; if (del != NULL) - (*del)(lst->content); + (*del)(lst->data); free(lst); } diff --git a/src/lst/ft_lstdestroy.c b/src/lst/ft_lstdestroy.c new file mode 100644 index 0000000..5e55f04 --- /dev/null +++ b/src/lst/ft_lstdestroy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdestroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:39 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:02:37 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +/** +** \brief Destroy a list and set his pointer to NULL +** \param del Delete Function for data of each node +*/ + +void ft_lstdestroy(t_ftlst **lst, void (*del)(void *)) +{ + if (lst == NULL) + return ; + if (*lst == NULL) + return ; + ft_lstdestroy(&((*lst)->next), del); + ft_lstdelone(*lst, del); + *lst = NULL; +} diff --git a/src/lst/ft_lstiter.c b/src/lst/ft_lstiter.c index 9b2895b..39d870b 100644 --- a/src/lst/ft_lstiter.c +++ b/src/lst/ft_lstiter.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstiter_bonus.c :+: :+: :+: */ +/* ft_lstiter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,16 +10,20 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Iterate of list +** \param f Funtion applied to data of each node +*/ + void ft_lstiter(t_ftlst *lst, void (*f)(void *)) { if (f == NULL) return ; while (lst != NULL) { - (*f)(lst->content); + (*f)(lst->data); lst = lst->next; } } diff --git a/src/lst/ft_lstlast.c b/src/lst/ft_lstlast.c index 728cbf2..12fdeee 100644 --- a/src/lst/ft_lstlast.c +++ b/src/lst/ft_lstlast.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstlast_bonus.c :+: :+: :+: */ +/* ft_lstlast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Last node +** \return List's last node +*/ + t_ftlst *ft_lstlast(t_ftlst *lst) { if (lst == NULL) diff --git a/src/lst/ft_lstlfind.c b/src/lst/ft_lstlfind.c index c399b6e..fd7e688 100644 --- a/src/lst/ft_lstlfind.c +++ b/src/lst/ft_lstlfind.c @@ -16,7 +16,7 @@ t_ftlst *ft_lstlfind(t_ftlst *lst, t_ftcompar_func cmp, const void *ref) { if (lst == NULL) return (NULL); - if (cmp(ref, lst->content) == 0) + if (cmp(ref, lst->data) == 0) return (lst); return (ft_lstlfind(lst->next, cmp, ref)); } diff --git a/src/lst/ft_lstlsearch.c b/src/lst/ft_lstlsearch.c index f59b5de..11c528c 100644 --- a/src/lst/ft_lstlsearch.c +++ b/src/lst/ft_lstlsearch.c @@ -16,7 +16,7 @@ t_ftlst *ft_lstlsearch(t_ftlst *lst, t_ftcompar_func cmp, const void *ref) { if (lst == NULL) return (ft_lstnew(ref)); - if (cmp(ref, lst->content) == 0) + if (cmp(ref, lst->data) == 0) return (lst); if (lst->next == NULL) { diff --git a/src/lst/ft_lstmap.c b/src/lst/ft_lstmap.c index dda15de..bf96892 100644 --- a/src/lst/ft_lstmap.c +++ b/src/lst/ft_lstmap.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstmap_bonus.c :+: :+: :+: */ +/* ft_lstmap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,9 +10,16 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Clone a list and map a function to each node data +** \param lst Origin list +** \param f Function applied to each node's data +** \param del Delete function for cleanning up in case of failed allocation +** \return Mapped clone list +*/ + t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), void (*del)(void *)) { t_ftlst *mapped; @@ -23,12 +30,12 @@ t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), void (*del)(void *)) mapped = NULL; while (lst != NULL) { - if ((tmp = ft_lstnew((*f)(lst->content))) == NULL) + if ((tmp = ft_lstnew((*f)(lst->data))) == NULL) { - ft_lstclear(&mapped, del); + ft_lstdestroy(&mapped, del); return (NULL); } - ft_lstadd_back(&mapped, tmp); + ft_lstpush_back(&mapped, tmp); lst = lst->next; } return (mapped); @@ -41,9 +48,9 @@ t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), void (*del)(void *)) ** ** if (lst == NULL) ** return (NULL); -** if ((tmp = ft_lstnew(lst->content)) == NULL) +** if ((tmp = ft_lstnew(lst->data)) == NULL) ** return (NULL); -** tmp->content = (*f)(tmp->content); +** tmp->data = (*f)(tmp->data); ** tmp->next = ft_lstmap(lst->next, f); ** return (tmp); */ diff --git a/src/lst/ft_lstnew.c b/src/lst/ft_lstnew.c index 11cf223..41c8153 100644 --- a/src/lst/ft_lstnew.c +++ b/src/lst/ft_lstnew.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstnew_bonus.c :+: :+: :+: */ +/* ft_lstnew.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,16 +10,20 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" -t_ftlst *ft_lstnew(void const *content) +/** +** \brief Create a list node +** \param data Pointer to data of node +*/ + +t_ftlst *ft_lstnew(void const *data) { t_ftlst *elem; if ((elem = (t_ftlst*)malloc(sizeof(t_ftlst))) == NULL) return (NULL); - elem->content = (void*)content; + elem->data = (void*)data; elem->next = NULL; return (elem); } diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c index 5bf2c60..798bf83 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Delete head node and replace it with next node +** \param del Delete function for node data +*/ + void ft_lstpop_front(t_ftlst **lst, void (*del)(void *)) { t_ftlst *tmp; diff --git a/src/lst/ft_lstpush_back.c b/src/lst/ft_lstpush_back.c new file mode 100644 index 0000000..372c18c --- /dev/null +++ b/src/lst/ft_lstpush_back.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstpush_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:03 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:01:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +/** +** \brief Push new node to the list end +** \param new Pushed node +*/ + +void ft_lstpush_back(t_ftlst **alst, t_ftlst *new) +{ + if (alst == NULL) + return ; + if (*alst == NULL) + { + *alst = new; + return ; + } + ft_lstlast(*alst)->next = new; +} diff --git a/src/lst/ft_lstpush_front.c b/src/lst/ft_lstpush_front.c new file mode 100644 index 0000000..c17a586 --- /dev/null +++ b/src/lst/ft_lstpush_front.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstpush_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:25 by cacharle #+# #+# */ +/* Updated: 2019/10/18 12:16:06 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +/** +** \brief Push node to list front +** \param new Pushed node +*/ + +void ft_lstpush_front(t_ftlst **alst, t_ftlst *new) +{ + if (alst == NULL || new == NULL) + return ; + new->next = *alst; + *alst = new; +} diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index 03643fa..fdac710 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -10,9 +10,15 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Remove node on some condition +** \param cmp Comparison function, return 0 if equal +** \param ref Reference data passed has the first arg of `cmp` +** \param del Delete function to free removed node data +*/ + void ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp, const void *ref, t_ftdel_func del) { @@ -20,7 +26,7 @@ void ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp, if (lst == NULL || *lst == NULL) return ; - if (cmp(ref, (*lst)->content) == 0) + if (cmp(ref, (*lst)->data) == 0) { saved_next = (*lst)->next; ft_lstdelone(*lst, del); diff --git a/src/lst/ft_lstreverse.c b/src/lst/ft_lstreverse.c index 61c9daf..fd5259b 100644 --- a/src/lst/ft_lstreverse.c +++ b/src/lst/ft_lstreverse.c @@ -10,9 +10,12 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Reverse a list +*/ + void ft_lstreverse(t_ftlst **lst) { *lst = ft_lstreverse_ret(*lst); diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c index c115ac5..259af9e 100644 --- a/src/lst/ft_lstreverse_ret.c +++ b/src/lst/ft_lstreverse_ret.c @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Reverse list +** \return Pointer to reversed list +*/ + t_ftlst *ft_lstreverse_ret(t_ftlst *lst) { t_ftlst *tmp; diff --git a/src/lst/ft_lstsize.c b/src/lst/ft_lstsize.c index 922b581..6a92b99 100644 --- a/src/lst/ft_lstsize.c +++ b/src/lst/ft_lstsize.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstsize_bonus.c :+: :+: :+: */ +/* ft_lstsize.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief List size +** \return Number of node in list +*/ + int ft_lstsize(t_ftlst *lst) { int counter; diff --git a/src/lst/ft_lstsort.c b/src/lst/ft_lstsort.c index e1c9913..fbd046a 100644 --- a/src/lst/ft_lstsort.c +++ b/src/lst/ft_lstsort.c @@ -12,6 +12,12 @@ #include "libft_lst.h" +/** +** \brief Sort list +** \param cmp Comparison function, <0 if less, 0 if equal, >0 if greater +** \note Use merge sort algorithm +*/ + void ft_lstsort(t_ftlst **begin_list, t_ftcompar_func cmp) { t_ftlst *fast; diff --git a/src/lst/ft_lstsorted_merge.c b/src/lst/ft_lstsorted_merge.c index 4f5332c..0cd5721 100644 --- a/src/lst/ft_lstsorted_merge.c +++ b/src/lst/ft_lstsorted_merge.c @@ -12,6 +12,14 @@ #include "libft_lst.h" +/** +** \brief Merge sorted lists, the new list is also sorted +** \param l1 First list +** \param l2 Second list +** \param cmp Comparison function, <0 if less, 0 if equal, >0 if greater +** \return Pointer to first node of merged list +*/ + t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, t_ftcompar_func cmp) { t_ftlst *merged; @@ -21,7 +29,7 @@ t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, t_ftcompar_func cmp) return (l2); if (l2 == NULL) return (l1); - if (cmp(l1->content, l2->content) < 0) + if (cmp(l1->data, l2->data) < 0) { merged = l1; merged->next = ft_lstsorted_merge(l1->next, l2, cmp); -- cgit From 9316f2063255bd4a0abd5c38d4c065969a8980bb Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 1 Apr 2020 18:10:36 +0200 Subject: Norm compliant comment format, dirty script for doxygen comments --- src/lst/ft_lstdelone.c | 2 +- src/lst/ft_lstdestroy.c | 2 +- src/lst/ft_lstiter.c | 2 +- src/lst/ft_lstlast.c | 2 +- src/lst/ft_lstmap.c | 2 +- src/lst/ft_lstnew.c | 2 +- src/lst/ft_lstpop_front.c | 2 +- src/lst/ft_lstpush_back.c | 2 +- src/lst/ft_lstpush_front.c | 2 +- src/lst/ft_lstremove_if.c | 2 +- src/lst/ft_lstreverse.c | 2 +- src/lst/ft_lstreverse_ret.c | 2 +- src/lst/ft_lstsize.c | 2 +- src/lst/ft_lstsort.c | 2 +- src/lst/ft_lstsorted_merge.c | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/lst') diff --git a/src/lst/ft_lstdelone.c b/src/lst/ft_lstdelone.c index 40e25cd..3dfbbbb 100644 --- a/src/lst/ft_lstdelone.c +++ b/src/lst/ft_lstdelone.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Delete list node ** \param del Delete function for node's data */ diff --git a/src/lst/ft_lstdestroy.c b/src/lst/ft_lstdestroy.c index 5e55f04..35da2a5 100644 --- a/src/lst/ft_lstdestroy.c +++ b/src/lst/ft_lstdestroy.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Destroy a list and set his pointer to NULL ** \param del Delete Function for data of each node */ diff --git a/src/lst/ft_lstiter.c b/src/lst/ft_lstiter.c index 39d870b..e46b507 100644 --- a/src/lst/ft_lstiter.c +++ b/src/lst/ft_lstiter.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Iterate of list ** \param f Funtion applied to data of each node */ diff --git a/src/lst/ft_lstlast.c b/src/lst/ft_lstlast.c index 12fdeee..97b853d 100644 --- a/src/lst/ft_lstlast.c +++ b/src/lst/ft_lstlast.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Last node ** \return List's last node */ diff --git a/src/lst/ft_lstmap.c b/src/lst/ft_lstmap.c index bf96892..3182bb0 100644 --- a/src/lst/ft_lstmap.c +++ b/src/lst/ft_lstmap.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Clone a list and map a function to each node data ** \param lst Origin list ** \param f Function applied to each node's data diff --git a/src/lst/ft_lstnew.c b/src/lst/ft_lstnew.c index 41c8153..1616b71 100644 --- a/src/lst/ft_lstnew.c +++ b/src/lst/ft_lstnew.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Create a list node ** \param data Pointer to data of node */ diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c index 798bf83..a61350a 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Delete head node and replace it with next node ** \param del Delete function for node data */ diff --git a/src/lst/ft_lstpush_back.c b/src/lst/ft_lstpush_back.c index 372c18c..1dca078 100644 --- a/src/lst/ft_lstpush_back.c +++ b/src/lst/ft_lstpush_back.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Push new node to the list end ** \param new Pushed node */ diff --git a/src/lst/ft_lstpush_front.c b/src/lst/ft_lstpush_front.c index c17a586..85df649 100644 --- a/src/lst/ft_lstpush_front.c +++ b/src/lst/ft_lstpush_front.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Push node to list front ** \param new Pushed node */ diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index fdac710..4070355 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Remove node on some condition ** \param cmp Comparison function, return 0 if equal ** \param ref Reference data passed has the first arg of `cmp` diff --git a/src/lst/ft_lstreverse.c b/src/lst/ft_lstreverse.c index fd5259b..7c2778d 100644 --- a/src/lst/ft_lstreverse.c +++ b/src/lst/ft_lstreverse.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Reverse a list */ diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c index 259af9e..36c0c5c 100644 --- a/src/lst/ft_lstreverse_ret.c +++ b/src/lst/ft_lstreverse_ret.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Reverse list ** \return Pointer to reversed list */ diff --git a/src/lst/ft_lstsize.c b/src/lst/ft_lstsize.c index 6a92b99..3c6956b 100644 --- a/src/lst/ft_lstsize.c +++ b/src/lst/ft_lstsize.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief List size ** \return Number of node in list */ diff --git a/src/lst/ft_lstsort.c b/src/lst/ft_lstsort.c index fbd046a..9945a0f 100644 --- a/src/lst/ft_lstsort.c +++ b/src/lst/ft_lstsort.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Sort list ** \param cmp Comparison function, <0 if less, 0 if equal, >0 if greater ** \note Use merge sort algorithm diff --git a/src/lst/ft_lstsorted_merge.c b/src/lst/ft_lstsorted_merge.c index 0cd5721..995785f 100644 --- a/src/lst/ft_lstsorted_merge.c +++ b/src/lst/ft_lstsorted_merge.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Merge sorted lists, the new list is also sorted ** \param l1 First list ** \param l2 Second list -- cgit