Everything compiles to object file and everything passes norminette.
Nothing was tested by running a program.
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_create_elem.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 11:24:10 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 14:13:45 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+t_list *ft_create_elem(void *data)
+{
+ t_list *new_elem;
+
+ new_elem = malloc(sizeof(t_list));
+ if (new_elem)
+ {
+ new_elem->data = data;
+ new_elem->next = NULL;
+ }
+ return (new_elem);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_push_front.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 11:27:15 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 14:16:03 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+t_list *ft_create_elem(void *data)
+{
+ t_list *new_elem;
+
+ new_elem = malloc(sizeof(t_list));
+ if (new_elem)
+ {
+ new_elem->data = data;
+ new_elem->next = NULL;
+ }
+ return (new_elem);
+}
+
+void ft_list_push_front(t_list **begin_list, void *data)
+{
+ t_list *new_elem;
+
+ new_elem = ft_create_elem(data);
+ new_elem->next = *begin_list;
+ *begin_list = new_elem;
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_size.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 12:26:21 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 12:28:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+int ft_list_size(t_list *begin_list)
+{
+ int i;
+
+ i = 0;
+ while (begin_list)
+ {
+ ++i;
+ begin_list = begin_list->next;
+ }
+ return (i);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_last.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 12:29:08 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 12:35:08 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+t_list *ft_list_last(t_list *begin_list)
+{
+ if (!begin_list)
+ return (begin_list);
+ while (begin_list->next)
+ begin_list = begin_list->next;
+ return (begin_list);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_push_back.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 12:40:16 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 14:14:46 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+t_list *ft_list_last(t_list *begin_list)
+{
+ if (!begin_list)
+ return (begin_list);
+ while (begin_list->next)
+ begin_list = begin_list->next;
+ return (begin_list);
+}
+
+t_list *ft_create_elem(void *data)
+{
+ t_list *new_elem;
+
+ new_elem = malloc(sizeof(t_list));
+ if (new_elem)
+ {
+ new_elem->data = data;
+ new_elem->next = NULL;
+ }
+ return (new_elem);
+}
+
+void ft_list_push_back(t_list **begin_list, void *data)
+{
+ t_list *last_elem;
+
+ last_elem = ft_list_last(*begin_list);
+ last_elem->next = ft_create_elem(data);
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_push_strs.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 12:45:53 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:48:20 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+t_list *ft_create_elem(void *data)
+{
+ t_list *new_elem;
+
+ new_elem = malloc(sizeof(t_list));
+ if (new_elem)
+ {
+ new_elem->data = data;
+ new_elem->next = NULL;
+ }
+ return (new_elem);
+}
+
+void ft_list_clear(t_list *begin_list, void (*free_fct)(void*))
+{
+ t_list *cur;
+ t_list *next;
+
+ cur = begin_list;
+ while (cur)
+ {
+ free_fct(cur->data);
+ next = cur->next;
+ free(cur);
+ cur = next;
+ }
+ return ;
+}
+
+t_list *ft_list_push_strs(int size, char **strs)
+{
+ t_list *beginning;
+ t_list *current_el;
+ int i;
+
+ beginning = NULL;
+ i = 0;
+ if (size > 0)
+ beginning = ft_create_elem(strs[i++]);
+ current_el = beginning;
+ while (i < size)
+ {
+ current_el->next = ft_create_elem(strs[i++]);
+ if (!current_el->next)
+ {
+ ft_list_clear(beginning, &free);
+ return (NULL);
+ }
+ current_el = current_el->next;
+ }
+ return (beginning);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_at.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 14:19:21 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 14:37:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+t_list *ft_list_at(t_list *begin_list, unsigned int nbr)
+{
+ unsigned int i;
+ t_list *el;
+
+ i = 0;
+ el = begin_list;
+ while (i < nbr && el)
+ {
+ el = el->next;
+ ++i;
+ }
+ return (el);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_clear.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 14:17:41 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 14:19:43 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+void ft_list_clear(t_list *begin_list, void (*free_fct)(void*))
+{
+ t_list *cur;
+ t_list *next;
+
+ cur = begin_list;
+ while (cur)
+ {
+ free_fct(cur->data);
+ next = cur->next;
+ free(cur);
+ cur = next;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_reverse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 14:22:47 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:39:39 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_list.h"
+
+void ft_list_reverse(t_list **begin_list)
+{
+ t_list *prev;
+ t_list *current;
+ t_list *next;
+
+ prev = NULL;
+ current = *begin_list;
+ while (current)
+ {
+ next = current->next;
+ current->next = prev;
+ prev = current;
+ current = next;
+ }
+ *begin_list = prev;
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_foreach.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 14:38:44 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 14:46:49 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+void ft_list_foreach(t_list *begin_list, void (*f)(void*))
+{
+ while (begin_list)
+ {
+ f(begin_list->data);
+ begin_list = begin_list->next;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_foreach_if.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 14:42:33 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 18:02:23 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+void ft_list_foreach_if(t_list *begin_list, void (*f)(void*),
+ void *data_ref, int (*cmp)())
+{
+ while (begin_list)
+ {
+ if (cmp(begin_list->data, data_ref) == 0)
+ f(begin_list->data);
+ begin_list = begin_list->next;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_find.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 14:47:42 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:44:22 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+#include "ft_list.h"
+
+t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)())
+{
+ while (begin_list)
+ {
+ if (cmp(begin_list->data, data_ref) == 0)
+ return (begin_list);
+ begin_list = begin_list->next;
+ }
+ return (NULL);
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_remove_if.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 14:49:53 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:51:00 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+void remove_next_el(t_list *prev, t_list **cur, void (*free_fct)(void*))
+{
+ prev->next = (*cur)->next;
+ free_fct((*cur)->data);
+ free(*cur);
+ *cur = prev->next;
+ return ;
+}
+
+void ft_list_remove_if(t_list **begin_list, void *data_ref,
+ int (*cmp)(), void (*free_fct)(void*))
+{
+ t_list *prev;
+
+ prev = NULL;
+ while (*begin_list)
+ {
+ if (cmp((*begin_list)->data, data_ref) == 0)
+ remove_next_el(prev, begin_list, free_fct);
+ else
+ *begin_list = (*begin_list)->next;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_merge.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 15:09:00 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:40:47 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+t_list *ft_list_last(t_list *begin_list)
+{
+ if (!begin_list)
+ return (begin_list);
+ while (begin_list->next)
+ begin_list = begin_list->next;
+ return (begin_list);
+}
+
+void ft_list_merge(t_list **begin_list1, t_list *begin_list2)
+{
+ t_list *last;
+
+ if (!*begin_list1)
+ {
+ *begin_list1 = begin_list2;
+ return ;
+ }
+ last = ft_list_last(*begin_list1);
+ last->next = begin_list2;
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_sort.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 15:13:29 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:48:42 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+int ft_list_size(t_list *begin_list)
+{
+ int i;
+
+ i = 0;
+ while (begin_list)
+ {
+ ++i;
+ begin_list = begin_list->next;
+ }
+ return (i);
+}
+
+void ft_swap(void **data1, void **data2)
+{
+ void *temp;
+
+ temp = *data1;
+ *data1 = *data2;
+ *data2 = temp;
+ return ;
+}
+
+void ft_max_to_end(t_list *begin_list, int (*cmp)(), int size)
+{
+ int i;
+
+ i = 0;
+ while (i < size - 1)
+ {
+ if (cmp(begin_list->data, begin_list->next->data) > 0)
+ ft_swap(&(begin_list->data), &(begin_list->next->data));
+ begin_list = begin_list->next;
+ }
+ return ;
+}
+
+void ft_list_sort(t_list **begin_list, int (*cmp)())
+{
+ int size;
+ int i;
+
+ size = ft_list_size(*begin_list);
+ i = 0;
+ while (i < size)
+ {
+ ft_max_to_end(*begin_list, cmp, size - i);
+ ++i;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_reverse_fun.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 15:45:46 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:41:28 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+int ft_list_size(t_list *begin_list)
+{
+ int i;
+
+ i = 0;
+ while (begin_list)
+ {
+ ++i;
+ begin_list = begin_list->next;
+ }
+ return (i);
+}
+
+void ft_swap(void **data1, void **data2)
+{
+ void *temp;
+
+ temp = *data1;
+ *data1 = *data2;
+ *data2 = temp;
+ return ;
+}
+
+void ft_first_to_end(t_list *begin_list, int size)
+{
+ int i;
+
+ i = 0;
+ while (i < size - 1)
+ {
+ ft_swap(&(begin_list->data), &(begin_list->next->data));
+ begin_list = begin_list->next;
+ }
+ return ;
+}
+
+// This algorithm could be vastly faster,
+// this implementation performs n^2/2 swaps but only n/2 is necessary
+void ft_list_reverse_fun(t_list *begin_list)
+{
+ int i;
+ int size;
+
+ size = ft_list_size(begin_list);
+ i = 0;
+ while (i < size)
+ {
+ ft_first_to_end(begin_list, size - i);
+ ++i;
+ }
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sorted_list_insert.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 15:53:26 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:51:43 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include "ft_list.h"
+
+t_list *ft_create_elem(void *data)
+{
+ t_list *new_elem;
+
+ new_elem = malloc(sizeof(t_list));
+ if (new_elem)
+ {
+ new_elem->data = data;
+ new_elem->next = NULL;
+ }
+ return (new_elem);
+}
+
+void insert_after(t_list *prev, void *data)
+{
+ t_list *new;
+
+ new = ft_create_elem(data);
+ if (!new)
+ return ;
+ new->next = prev->next;
+ prev->next = new->next;
+ return ;
+}
+
+void ft_list_push_front(t_list **begin_list, void *data)
+{
+ t_list *new_elem;
+
+ new_elem = ft_create_elem(data);
+ new_elem->next = *begin_list;
+ *begin_list = new_elem;
+ return ;
+}
+
+void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)())
+{
+ t_list *prev;
+ t_list *cur;
+
+ if (!*begin_list)
+ {
+ *begin_list = ft_create_elem(data);
+ return ;
+ }
+ prev = NULL;
+ cur = *begin_list;
+ while (cur)
+ {
+ if (cmp(data, cur->data) <= 0)
+ break ;
+ prev = cur;
+ cur = cur->next;
+ }
+ if (prev)
+ insert_after(prev, data);
+ else
+ ft_list_push_front(begin_list, data);
+ return ;
+}
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 10:27:34 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 13:56:29 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FT_LIST_H
+# define FT_LIST_H
+
+typedef struct s_list
+{
+ struct s_list *next;
+ void *data;
+} t_list;
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sorted_list_merge.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/06/28 17:13:15 by ljiriste #+# #+# */
+/* Updated: 2023/06/28 17:50:12 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ft_list.h"
+
+void exchange_list(t_list *last_staying, t_list **first_other)
+{
+ t_list *new_other;
+
+ new_other = last_staying->next;
+ last_staying->next = *first_other;
+ *first_other = new_other;
+ return ;
+}
+
+void ft_sorted_list_merge(t_list **begin_list1, t_list *other_list,
+ int (*cmp)())
+{
+ t_list *main;
+
+ if (cmp((*begin_list1)->data, other_list->data) > 0)
+ {
+ main = other_list;
+ other_list = *begin_list1;
+ *begin_list1 = main;
+ }
+ else
+ main = *begin_list1;
+ while (main->next)
+ {
+ if (cmp(main->next->data, other_list->data) > 0)
+ exchange_list(main, &other_list);
+ main = main->next;
+ }
+ main->next = other_list;
+ return ;
+}