diff --git a/srcs/lst/ft_lstnew.c b/srcs/lst/ft_lstnew.c new file mode 100644 index 0000000..37f210b --- /dev/null +++ b/srcs/lst/ft_lstnew.c @@ -0,0 +1,14 @@ +#include "libft.h" + +t_list *ft_lstnew(void *data) +{ + t_list *node = (t_list *)malloc(sizeof(t_list)); + + if (!node) + return (NULL); + + node->data = data; + node->next = NULL; + + return node; +} \ No newline at end of file diff --git a/srcs/lst/ft_lstpop.c b/srcs/lst/ft_lstpop.c new file mode 100644 index 0000000..40dd665 --- /dev/null +++ b/srcs/lst/ft_lstpop.c @@ -0,0 +1,23 @@ +#include "libft.h" + +t_list *ft_lstpop(t_list **lst) +{ + t_list *current; + t_list *prev; + + if (!lst || !*lst) + return NULL; + current = *lst; + if (current->next == NULL) + { + *lst = NULL; + return current; + } + while (current->next) + { + prev = current; + current = current->next; + } + prev->next = NULL; + return current; +} diff --git a/srcs/lst/ft_lstpush.c b/srcs/lst/ft_lstpush.c new file mode 100644 index 0000000..1d87cf4 --- /dev/null +++ b/srcs/lst/ft_lstpush.c @@ -0,0 +1,22 @@ +#include "libft.h" + +void ft_lstpush(t_list **lst, t_list *node) +{ + t_list *current; + + if (!lst || !node) + return; + + node->next = NULL; + + if (*lst == NULL) + { + *lst = node; + return; + } + + current = *lst; + while (current->next != NULL) + current = current->next; + current->next = node; +} diff --git a/srcs/lst/ft_lstshift.c b/srcs/lst/ft_lstshift.c new file mode 100644 index 0000000..7a43812 --- /dev/null +++ b/srcs/lst/ft_lstshift.c @@ -0,0 +1,13 @@ +#include "libft.h" + +t_list *ft_lstshift(t_list **lst) +{ + t_list *first; + + if (!lst || !*lst) + return NULL; + first = *lst; + *lst = first->next; + first->next = NULL; + return first; +} diff --git a/srcs/lst/ft_lstsize.c b/srcs/lst/ft_lstsize.c new file mode 100644 index 0000000..2327fe0 --- /dev/null +++ b/srcs/lst/ft_lstsize.c @@ -0,0 +1,12 @@ +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int size = 0; + while (lst) + { + size++; + lst = lst->next; + } + return size; +} diff --git a/srcs/lst/ft_lstunshift.c b/srcs/lst/ft_lstunshift.c new file mode 100644 index 0000000..8d78989 --- /dev/null +++ b/srcs/lst/ft_lstunshift.c @@ -0,0 +1,9 @@ +#include "libft.h" + +void ft_lstunshift(t_list **lst, t_list *node) +{ + if (!lst || !node) + return; + node->next = *lst; + *lst = node; +}