Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderhammer91 authored Mar 22, 2023
1 parent 1014f76 commit ea41c26
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ft_lstadd_front.c
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;
}
}
48 changes: 48 additions & 0 deletions ft_lstclear.c
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);
}
38 changes: 38 additions & 0 deletions ft_lstdelone.c
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);
}
38 changes: 38 additions & 0 deletions ft_lstiter.c
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;
}
}
39 changes: 39 additions & 0 deletions ft_lstlast.c
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);
}

0 comments on commit ea41c26

Please sign in to comment.