Started from buttom go to the sky

This commit is contained in:
Raphaël 2024-04-28 19:59:01 +02:00
parent 96215449bd
commit f811e55dea
4781 changed files with 10121 additions and 1743 deletions

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_add_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 20:38:45 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:02:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_add_back.h"
#include "me/list/list_get_last.h"
void list_add_back(t_list **list, t_list *new)
{
if (*list)
list_get_last(*list)->next = new;
else
*list = new;
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_add_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 20:15:23 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:02:50 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_add_front.h"
#include "me/list/list_alloc_node.h"
void list_add_front(t_list **lst, t_list *new)
{
new->next = *lst;
*lst = new;
}

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_alloc_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 19:57:28 by maiboyer #+# #+# */
/* Updated: 2023/12/09 18:13:05 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_alloc_node.h"
#include "me/mem/mem_alloc.h"
t_list *list_alloc_node(void *content)
{
t_list *out;
out = mem_alloc(sizeof(t_list) * 1);
if (out == NULL)
return (NULL);
out->content = content;
out->next = NULL;
return (out);
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_free_all.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 21:35:20 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:03:34 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_free_all.h"
#include <stdlib.h>
void list_free_all(t_list **lst, void (*del)(void *))
{
t_list *tmp;
if (lst == NULL || del == NULL)
return ;
while (*lst)
{
del((*lst)->content);
tmp = *lst;
*lst = (*lst)->next;
free(tmp);
}
*lst = NULL;
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_free_one.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 21:30:20 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:03:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_free_one.h"
#include <stdlib.h>
void list_free_one(t_list *lst, void (*del)(void *))
{
if (lst == NULL || del == NULL)
return ;
del(lst->content);
free(lst);
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_get_last.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 20:37:08 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:03:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_get_last.h"
t_list *list_get_last(t_list *list)
{
t_list *head;
head = list;
if (head == NULL)
return (NULL);
while (head->next)
head = head->next;
return (head);
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_iter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 21:39:05 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:03:55 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_iter.h"
void list_iter(t_list *list, void (*f)(void *))
{
while (list)
{
f(list->content);
list = list->next;
}
}

40
stdme/src/list/list_map.c Normal file
View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 21:40:24 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:05:20 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_alloc_node.h"
#include "me/list/list_free_all.h"
#include "me/list/list_map.h"
#include <stdlib.h>
t_list *list_map(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
void *data;
t_list new;
t_list *cursor;
new = (t_list){.next = NULL, .content = NULL};
cursor = &new;
while (lst)
{
data = f(lst->content);
cursor->next = list_alloc_node(data);
if (cursor->next == NULL)
{
del(data);
list_free_all(&new.next, del);
return (NULL);
}
cursor = cursor->next;
lst = lst->next;
}
return (new.next);
}

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_size.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 20:23:19 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:05:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/list/list_size.h"
t_usize list_size(t_list *lst)
{
t_list *head;
t_usize idx;
head = lst;
idx = 0;
while (head)
{
head = head->next;
idx++;
}
return (idx);
}