-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1014f76
commit ea41c26
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_lstadd_front.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/20 16:52:10 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/21 15:35:52 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
PROTOTYPE | ||
void ft_lstadd_front(t_list **lst, t_list *new); | ||
PARAMETERS | ||
lst: The address of a pointer to the first link of a list. | ||
new: The address of a pointer to the node to be added to the list. | ||
(no return value.) | ||
(no external functs.) | ||
DESCRIPTION | ||
Adds the node 'new' at the beginning of the list. | ||
*/ | ||
#include "libft.h" | ||
|
||
void ft_lstadd_front(t_list **lst, t_list *new) | ||
{ | ||
if (lst) | ||
{ | ||
new -> next = *lst; | ||
*lst = new; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_lstclear.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/20 18:31:26 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/20 18:57:41 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
PROTOTYPE | ||
void ft_lstclear(t_list **lst, void (*del)(void *)); | ||
PARAMETERS | ||
lst: The address of a pointer to a node. | ||
del: The address of the function used to delete | ||
the content of the node. | ||
no return value | ||
EXTERNAL FUNCTIONS | ||
free | ||
DESCRIPTION | ||
Deletes and frees the given node and every | ||
successor of that node, using the function ’del’ | ||
and free(3). | ||
Finally, the pointer to the list must be set to | ||
NULL. | ||
*/ | ||
#include "libft.h" | ||
|
||
void ft_lstclear(t_list **lst, void (*del)(void *)) | ||
{ | ||
t_list *temp; | ||
|
||
if (!lst || !del) | ||
return ; | ||
while (*lst) | ||
{ | ||
temp = (*lst)->next; | ||
ft_lstdelone(*lst, del); | ||
*lst = temp; | ||
} | ||
*lst = (NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_lstdelone.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/20 17:47:26 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/22 12:42:47 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
PROTOTYPE | ||
void ft_lstdelone(t_list *lst, void (*del)(void *)); | ||
PARAMETERS | ||
lst: The node to free | ||
del: The address of the function used to delete the content. | ||
no return | ||
EXTERNAL FUNCTIONS | ||
free | ||
DESCRIPTION | ||
Takes as a parameter a node and frees the memory of the node's content | ||
using the function 'del' given as a parameter and free the node. The memory | ||
of 'next' must not be freed. | ||
*/ | ||
#include "libft.h" | ||
|
||
void ft_lstdelone(t_list *lst, void (*del)(void *)) | ||
{ | ||
if (!lst) | ||
return ; | ||
del(lst->content); | ||
free(lst); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_lstiter.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/20 18:59:55 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/20 19:09:52 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
PROTOTYPE | ||
void ft_lstiter(t_list *lst, void (*f)(void *)); | ||
PARAMETERS | ||
lst: The address of a pointer to a node. | ||
f: The address of the function used to iterate on | ||
the list. | ||
No return or external functions. | ||
DESCRIPTION | ||
Iterates the list ’lst’ and applies the function | ||
’f’ on the content of each node. | ||
*/ | ||
#include "libft.h" | ||
|
||
void ft_lstiter(t_list *lst, void (*f)(void *)) | ||
{ | ||
if (!lst || !f) | ||
return ; | ||
while (lst) | ||
{ | ||
(*f)(lst->content); | ||
lst = lst->next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_lstlast.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/20 17:20:23 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/20 17:29:26 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
PROTOTYPE | ||
t_list *ft_lstlast(t_list *lst); | ||
PARAMETERS | ||
lst: The beginning of the list. | ||
RETURN | ||
Last node of the list | ||
no external functs. | ||
DESCRIPTION | ||
returns the last node of the list. | ||
*/ | ||
#include "libft.h" | ||
|
||
t_list *ft_lstlast(t_list *lst) | ||
{ | ||
while (lst) | ||
{ | ||
if (lst ->next) | ||
lst = lst->next; | ||
else | ||
return (lst); | ||
} | ||
return (NULL); | ||
} |