feat: ft_listinsert
This commit is contained in:
parent
a9a3c473d5
commit
1cab237921
4
Makefile
4
Makefile
|
@ -6,7 +6,7 @@
|
||||||
# By: gbrochar <marvin@42.fr> +#+ +:+ +#+ #
|
# By: gbrochar <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2015/11/27 19:26:17 by gbrochar #+# #+# #
|
# Created: 2015/11/27 19:26:17 by gbrochar #+# #+# #
|
||||||
# Updated: 2024/10/13 18:44:22 by gbrochar ### ########.fr #
|
# Updated: 2024/10/14 20:59:43 by gbrochar ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ ft_strchr.c ft_strclr.c ft_strcmp.c ft_strcpy.c ft_strdel.c ft_strdup.c \
|
||||||
ft_strequ.c ft_striter.c ft_striteri.c ft_strjoin.c ft_strlcat.c ft_strlen.c \
|
ft_strequ.c ft_striter.c ft_striteri.c ft_strjoin.c ft_strlcat.c ft_strlen.c \
|
||||||
ft_strmap.c ft_strmapi.c ft_strncat.c ft_strncmp.c ft_strncpy.c ft_strnequ.c \
|
ft_strmap.c ft_strmapi.c ft_strncat.c ft_strncmp.c ft_strncpy.c ft_strnequ.c \
|
||||||
ft_strnew.c ft_strnstr.c ft_strrchr.c ft_strsplit.c ft_strstr.c ft_strsub.c \
|
ft_strnew.c ft_strnstr.c ft_strrchr.c ft_strsplit.c ft_strstr.c ft_strsub.c \
|
||||||
ft_strtrim.c ft_swap.c ft_tolower.c ft_toupper.c ft_lstadd_back.c
|
ft_strtrim.c ft_swap.c ft_tolower.c ft_toupper.c ft_lstadd_back.c ft_lstinsert.c
|
||||||
|
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
void ft_lstadd_back(t_list **alst, t_list *new)
|
void ft_lstadd_back(t_list **alst, t_list *new)
|
||||||
{
|
{
|
||||||
|
if (!alst) {
|
||||||
|
(*alst) = new;
|
||||||
|
return;
|
||||||
|
}
|
||||||
while ((*alst)->next)
|
while ((*alst)->next)
|
||||||
alst = &(*alst)->next;
|
alst = &(*alst)->next;
|
||||||
(*alst)->next = new;
|
(*alst)->next = new;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstinsert(t_list **lst, t_list *new, int (*f)(t_list *a, t_list *b)) {
|
||||||
|
if (!(*lst)) {
|
||||||
|
*lst = new;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while ((*lst)->next && f(new, *lst) < 0) {
|
||||||
|
lst = &(*lst)->next;
|
||||||
|
}
|
||||||
|
t_list *tmp = (*lst)->next;
|
||||||
|
(*lst)->next = new;
|
||||||
|
new->next = tmp;
|
||||||
|
}
|
3
libft.h
3
libft.h
|
@ -6,7 +6,7 @@
|
||||||
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2015/11/24 12:52:28 by gbrochar #+# #+# */
|
/* Created: 2015/11/24 12:52:28 by gbrochar #+# #+# */
|
||||||
/* Updated: 2024/10/13 18:45:37 by gbrochar ### ########.fr */
|
/* Updated: 2024/10/14 21:01:47 by gbrochar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ typedef struct s_list
|
||||||
|
|
||||||
void ft_lstadd(t_list **alst, t_list *new);
|
void ft_lstadd(t_list **alst, t_list *new);
|
||||||
void ft_lstadd_back(t_list **alst, t_list *new);
|
void ft_lstadd_back(t_list **alst, t_list *new);
|
||||||
|
void ft_lstinsert(t_list **lst, t_list *new, int (*f)(t_list *a, t_list *b));
|
||||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||||
|
|
Loading…
Reference in New Issue