aboutsummaryrefslogtreecommitdiff
path: root/src/lst
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-09-18 16:39:52 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-09-18 16:39:52 +0200
commitdd0c485ac4975b7dd6d2e230213be1da50d0a065 (patch)
tree5fbd967f8b95c72fbb696bb089c2cc349d28b61f /src/lst
parent3c3f1115f6e9a9b914e2dcbd796501ca7ce85342 (diff)
downloadlibft-dd0c485ac4975b7dd6d2e230213be1da50d0a065.tar.gz
libft-dd0c485ac4975b7dd6d2e230213be1da50d0a065.tar.bz2
libft-dd0c485ac4975b7dd6d2e230213be1da50d0a065.zip
Removing unnecessary stuffmalloc
Diffstat (limited to 'src/lst')
-rw-r--r--src/lst/ft_lstadd_back.c26
-rw-r--r--src/lst/ft_lstadd_front.c22
-rw-r--r--src/lst/ft_lstbsearch.c65
-rw-r--r--src/lst/ft_lstclear.c25
-rw-r--r--src/lst/ft_lstdelone.c23
-rw-r--r--src/lst/ft_lstiter.c25
-rw-r--r--src/lst/ft_lstlast.c23
-rw-r--r--src/lst/ft_lstlfind.c22
-rw-r--r--src/lst/ft_lstlsearch.c27
-rw-r--r--src/lst/ft_lstmap.c49
-rw-r--r--src/lst/ft_lstnew.c25
-rw-r--r--src/lst/ft_lstpop_front.c25
-rw-r--r--src/lst/ft_lstremove_if.c32
-rw-r--r--src/lst/ft_lstreverse.c19
-rw-r--r--src/lst/ft_lstreverse_ret.c28
-rw-r--r--src/lst/ft_lstsize.c27
-rw-r--r--src/lst/ft_lstsort.c40
-rw-r--r--src/lst/ft_lstsorted_merge.c35
18 files changed, 0 insertions, 538 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* 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 <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* 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
deleted file mode 100644
index d694209..0000000
--- a/src/lst/ft_lstbsearch.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstbsearch.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/30 09:17:51 by cacharle #+# #+# */
-/* Updated: 2020/02/17 03:03:21 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-static t_ftlst *st_lstmiddle(t_ftlst *lst, t_ftlst *last)
-{
- t_ftlst *slow;
- t_ftlst *fast;
-
- if (lst == NULL)
- return (NULL);
- slow = lst;
- fast = lst;
- while (fast != last)
- {
- fast = fast->next;
- if (fast == last)
- break ;
- slow = slow->next;
- fast = fast->next;
- }
- return (slow);
-}
-
-static t_ftlst *st_lstbsearch_rec(t_ftlst *lst, t_ftlst *last,
- t_ftcompar_func cmp, const void *ref)
-{
- int res;
- t_ftlst *mid;
-
- if (lst == NULL)
- return (NULL);
- mid = st_lstmiddle(lst, last);
- if (mid == NULL)
- return (NULL);
- if (mid->next == NULL)
- {
- if (cmp(ref, mid->content) == 0)
- return (mid);
- return (NULL);
- }
- res = cmp(ref, mid->next->content);
- if (res < 0)
- return (st_lstbsearch_rec(lst, mid, cmp, ref));
- else if (res > 0)
- return (st_lstbsearch_rec(mid->next->next, NULL, cmp, ref));
- return (mid->next);
-}
-
-t_ftlst *ft_lstbsearch(t_ftlst *lst, t_ftcompar_func cmp,
- const void *ref)
-{
- return (st_lstbsearch_rec(lst, NULL, cmp, ref));
-}
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 <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* 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
deleted file mode 100644
index 63dcc35..0000000
--- a/src/lst/ft_lstdelone.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstdelone_bonus.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/09 09:03:02 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:02:31 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-void ft_lstdelone(t_ftlst *lst, void (*del)(void *))
-{
- if (lst == NULL)
- return ;
- if (del != NULL)
- (*del)(lst->content);
- free(lst);
-}
diff --git a/src/lst/ft_lstiter.c b/src/lst/ft_lstiter.c
deleted file mode 100644
index 9b2895b..0000000
--- a/src/lst/ft_lstiter.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstiter_bonus.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/09 09:03:22 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:01:39 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-void ft_lstiter(t_ftlst *lst, void (*f)(void *))
-{
- if (f == NULL)
- return ;
- while (lst != NULL)
- {
- (*f)(lst->content);
- lst = lst->next;
- }
-}
diff --git a/src/lst/ft_lstlast.c b/src/lst/ft_lstlast.c
deleted file mode 100644
index 728cbf2..0000000
--- a/src/lst/ft_lstlast.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstlast_bonus.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/09 09:03:40 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:02:26 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-t_ftlst *ft_lstlast(t_ftlst *lst)
-{
- if (lst == NULL)
- return (NULL);
- while (lst->next != NULL)
- lst = lst->next;
- return (lst);
-}
diff --git a/src/lst/ft_lstlfind.c b/src/lst/ft_lstlfind.c
deleted file mode 100644
index 92d37d8..0000000
--- a/src/lst/ft_lstlfind.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstlfind.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/17 03:04:52 by cacharle #+# #+# */
-/* Updated: 2020/02/19 02:03:11 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft_lst.h"
-
-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)
- return (lst);
- return (ft_lstlfind(lst->next, cmp, ref));
-}
diff --git a/src/lst/ft_lstlsearch.c b/src/lst/ft_lstlsearch.c
deleted file mode 100644
index 8d2acc8..0000000
--- a/src/lst/ft_lstlsearch.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstlsearch.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/17 02:57:12 by cacharle #+# #+# */
-/* Updated: 2020/02/17 03:35:45 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft_lst.h"
-
-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)
- return (lst);
- if (lst->next == NULL)
- {
- lst->next = ft_lstnew(ref);
- return (lst->next);
- }
- return (ft_lstlsearch(lst->next, cmp, ref));
-}
diff --git a/src/lst/ft_lstmap.c b/src/lst/ft_lstmap.c
deleted file mode 100644
index dda15de..0000000
--- a/src/lst/ft_lstmap.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstmap_bonus.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/09 09:03:57 by cacharle #+# #+# */
-/* Updated: 2020/02/15 23:11:42 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), void (*del)(void *))
-{
- t_ftlst *mapped;
- t_ftlst *tmp;
-
- if (lst == NULL || f == NULL)
- return (NULL);
- mapped = NULL;
- while (lst != NULL)
- {
- if ((tmp = ft_lstnew((*f)(lst->content))) == NULL)
- {
- ft_lstclear(&mapped, del);
- return (NULL);
- }
- ft_lstadd_back(&mapped, tmp);
- lst = lst->next;
- }
- return (mapped);
-}
-
-/*
-** Rest in peace, my beautiful recursion.
-**
-** t_ftlst *tmp;
-**
-** if (lst == NULL)
-** return (NULL);
-** if ((tmp = ft_lstnew(lst->content)) == NULL)
-** return (NULL);
-** tmp->content = (*f)(tmp->content);
-** tmp->next = ft_lstmap(lst->next, f);
-** return (tmp);
-*/
diff --git a/src/lst/ft_lstnew.c b/src/lst/ft_lstnew.c
deleted file mode 100644
index 11cf223..0000000
--- a/src/lst/ft_lstnew.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstnew_bonus.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/09 09:01:16 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:01:35 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-t_ftlst *ft_lstnew(void const *content)
-{
- t_ftlst *elem;
-
- if ((elem = (t_ftlst*)malloc(sizeof(t_ftlst))) == NULL)
- return (NULL);
- elem->content = (void*)content;
- elem->next = NULL;
- return (elem);
-}
diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c
deleted file mode 100644
index ff386f9..0000000
--- a/src/lst/ft_lstpop_front.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstpop_front_bonus.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/25 03:32:51 by cacharle #+# #+# */
-/* Updated: 2020/01/15 12:46:28 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-void ft_lstpop_front(t_ftlst **lst, void (*del)(void *))
-{
- t_ftlst *tmp;
-
- if (lst == NULL || *lst == NULL)
- return ;
- tmp = (*lst)->next;
- ft_lstdelone(*lst, del);
- *lst = tmp;
-}
diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c
deleted file mode 100644
index 5221ae4..0000000
--- a/src/lst/ft_lstremove_if.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstremove_if.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/30 09:36:49 by cacharle #+# #+# */
-/* Updated: 2020/02/19 02:06:22 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-void ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp,
- const void *ref, t_ftdel_func del)
-{
- t_ftlst *saved_next;
-
- if (lst == NULL || *lst == NULL)
- return ;
- if (cmp(ref, (*lst)->content) == 0)
- {
- saved_next = (*lst)->next;
- ft_lstdelone(*lst, del);
- *lst = saved_next;
- ft_lstremove_if(lst, cmp, ref, del);
- return ;
- }
- ft_lstremove_if(&(*lst)->next, cmp, ref, del);
-}
diff --git a/src/lst/ft_lstreverse.c b/src/lst/ft_lstreverse.c
deleted file mode 100644
index 61c9daf..0000000
--- a/src/lst/ft_lstreverse.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstreverse.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/15 12:49:14 by cacharle #+# #+# */
-/* Updated: 2020/02/15 22:53:23 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-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
deleted file mode 100644
index c115ac5..0000000
--- a/src/lst/ft_lstreverse_ret.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstreverse_ret.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/15 12:51:15 by cacharle #+# #+# */
-/* Updated: 2020/02/10 02:20:21 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-t_ftlst *ft_lstreverse_ret(t_ftlst *lst)
-{
- t_ftlst *tmp;
-
- if (lst == NULL)
- return (NULL);
- if (lst->next == NULL)
- return (lst);
- tmp = ft_lstreverse_ret(lst->next);
- lst->next->next = lst;
- lst->next = NULL;
- return (tmp);
-}
diff --git a/src/lst/ft_lstsize.c b/src/lst/ft_lstsize.c
deleted file mode 100644
index 922b581..0000000
--- a/src/lst/ft_lstsize.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstsize_bonus.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/09 09:04:28 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:01:44 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-#include "libft_lst.h"
-
-int ft_lstsize(t_ftlst *lst)
-{
- int counter;
-
- counter = 0;
- while (lst != NULL)
- {
- counter++;
- lst = lst->next;
- }
- return (counter);
-}
diff --git a/src/lst/ft_lstsort.c b/src/lst/ft_lstsort.c
deleted file mode 100644
index e1c9913..0000000
--- a/src/lst/ft_lstsort.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstsort.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/10 01:53:55 by cacharle #+# #+# */
-/* Updated: 2020/02/16 02:18:05 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft_lst.h"
-
-void ft_lstsort(t_ftlst **begin_list, t_ftcompar_func cmp)
-{
- t_ftlst *fast;
- t_ftlst *slow;
- t_ftlst *middle;
-
- if (begin_list == NULL || *begin_list == NULL
- || (*begin_list)->next == NULL)
- return ;
- fast = (*begin_list)->next;
- slow = *begin_list;
- while (fast != NULL)
- {
- fast = fast->next;
- if (fast != NULL)
- {
- fast = fast->next;
- slow = slow->next;
- }
- }
- middle = slow->next;
- slow->next = NULL;
- ft_lstsort(begin_list, cmp);
- ft_lstsort(&middle, cmp);
- *begin_list = ft_lstsorted_merge(*begin_list, middle, cmp);
-}
diff --git a/src/lst/ft_lstsorted_merge.c b/src/lst/ft_lstsorted_merge.c
deleted file mode 100644
index 4f5332c..0000000
--- a/src/lst/ft_lstsorted_merge.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_lstsorted_merge.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/10 01:58:52 by cacharle #+# #+# */
-/* Updated: 2020/02/16 02:18:11 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft_lst.h"
-
-t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, t_ftcompar_func cmp)
-{
- t_ftlst *merged;
-
- merged = NULL;
- if (l1 == NULL)
- return (l2);
- if (l2 == NULL)
- return (l1);
- if (cmp(l1->content, l2->content) < 0)
- {
- merged = l1;
- merged->next = ft_lstsorted_merge(l1->next, l2, cmp);
- }
- else
- {
- merged = l2;
- merged->next = ft_lstsorted_merge(l1, l2->next, cmp);
- }
- return (merged);
-}