Started from buttom go to the sky
This commit is contained in:
parent
96215449bd
commit
f811e55dea
4781 changed files with 10121 additions and 1743 deletions
22
stdme/src/list/list_add_back.c
Normal file
22
stdme/src/list/list_add_back.c
Normal 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;
|
||||
}
|
||||
20
stdme/src/list/list_add_front.c
Normal file
20
stdme/src/list/list_add_front.c
Normal 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;
|
||||
}
|
||||
26
stdme/src/list/list_alloc_node.c
Normal file
26
stdme/src/list/list_alloc_node.c
Normal 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);
|
||||
}
|
||||
30
stdme/src/list/list_free_all.c
Normal file
30
stdme/src/list/list_free_all.c
Normal 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;
|
||||
}
|
||||
22
stdme/src/list/list_free_one.c
Normal file
22
stdme/src/list/list_free_one.c
Normal 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);
|
||||
}
|
||||
25
stdme/src/list/list_get_last.c
Normal file
25
stdme/src/list/list_get_last.c
Normal 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);
|
||||
}
|
||||
22
stdme/src/list/list_iter.c
Normal file
22
stdme/src/list/list_iter.c
Normal 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
40
stdme/src/list/list_map.c
Normal 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);
|
||||
}
|
||||
28
stdme/src/list/list_size.c
Normal file
28
stdme/src/list/list_size.c
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue