-
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
5310ee6
commit 551beb4
Showing
6 changed files
with
167 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,26 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_list.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: izenkri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/11 12:59:58 by zenkri #+# #+# */ | ||
/* Updated: 2024/01/13 19:39:40 by izenkri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef FT_LIST_H | ||
# define FT_LIST_H | ||
|
||
# include <stdlib.h> | ||
|
||
typedef struct s_list | ||
{ | ||
struct s_list *next; | ||
void *data; | ||
} t_list; | ||
|
||
t_list *ft_create_elem(void *data); | ||
|
||
#endif |
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,24 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_list_foreach_if.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: izenkri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/11 12:59:58 by zenkri #+# #+# */ | ||
/* Updated: 2024/01/13 19:40:25 by izenkri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_list.h" | ||
|
||
void ft_list_foreach_if(t_list *begin_list, | ||
void (*f)(void *), void *data_ref, int (*cmp)()) | ||
{ | ||
while (begin_list) | ||
{ | ||
if ((*cmp)(begin_list->data, data_ref) == 0) | ||
(*f)(begin_list->data); | ||
begin_list = begin_list->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,26 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_list.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: izenkri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/11 12:59:58 by zenkri #+# #+# */ | ||
/* Updated: 2024/01/13 19:41:20 by izenkri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef FT_LIST_H | ||
# define FT_LIST_H | ||
|
||
# include <stdlib.h> | ||
|
||
typedef struct s_list | ||
{ | ||
struct s_list *next; | ||
void *data; | ||
} t_list; | ||
|
||
t_list *ft_create_elem(void *data); | ||
|
||
#endif |
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,24 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_list_find.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: izenkri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/11 12:59:58 by zenkri #+# #+# */ | ||
/* Updated: 2024/01/13 19:41:44 by izenkri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_list.h" | ||
|
||
t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()) | ||
{ | ||
while (begin_list) | ||
{ | ||
if ((*cmp)(begin_list->data, data_ref) == 0) | ||
return (begin_list); | ||
begin_list = begin_list->next; | ||
} | ||
return (0); | ||
} |
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,27 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_list.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: izenkri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/11 12:59:58 by zenkri #+# #+# */ | ||
/* Updated: 2024/01/13 19:43:22 by izenkri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
||
#ifndef FT_LIST_H | ||
# define FT_LIST_H | ||
|
||
# include <stdlib.h> | ||
|
||
typedef struct s_list | ||
{ | ||
struct s_list *next; | ||
void *data; | ||
} t_list; | ||
|
||
t_list *ft_create_elem(void *data); | ||
|
||
#endif |
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,40 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_list_remove_if.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: izenkri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/12/11 12:59:58 by zenkri #+# #+# */ | ||
/* Updated: 2024/01/13 19:42:55 by izenkri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "ft_list.h" | ||
|
||
void ft_list_remove_if(t_list **begin_list, | ||
void *data_ref, int (*cmp)(), void (*free_fct)(void *)) | ||
{ | ||
t_list *list; | ||
t_list *tmp; | ||
|
||
list = *begin_list; | ||
while (list && list->next) | ||
{ | ||
if ((*cmp)(list->next->data, data_ref) == 0) | ||
{ | ||
tmp = list->next; | ||
list->next = list->next->next; | ||
(*free_fct)(tmp->data); | ||
free(tmp); | ||
} | ||
list = list->next; | ||
} | ||
list = *begin_list; | ||
if (list && (*cmp)(list->data, data_ref) == 0) | ||
{ | ||
*begin_list = list->next; | ||
(*free_fct)(list->data); | ||
free(list); | ||
} | ||
} |