Browse Source

8,10

master
Elouan MARTINET 4 years ago
parent
commit
ebe76ddf69
  1. 24
      ex08/ft_list.h
  2. 37
      ex08/ft_list_reverse.c
  3. 24
      ex10/ft_list.h
  4. 27
      ex10/ft_list_foreach_if.c

24
ex08/ft_list.h

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/16 12:37:12 by emartine #+# #+# */
/* Updated: 2017/08/16 12:37:14 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
# define FT_LIST_H
typedef struct s_list
{
struct s_list *next;
void *data;
} t_list;
t_list *ft_create_elem(void *data);
#endif

37
ex08/ft_list_reverse.c

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list_reverse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/16 13:57:05 by emartine #+# #+# */
/* Updated: 2017/08/17 15:53:35 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
void ft_list_reverse(t_list **begin_list)
{
t_list *last;
t_list *current;
t_list *previous;
if (!*begin_list || !(*begin_list)->next)
return ;
last = *begin_list;
while (last->next)
last = last->next;
current = last;
while ((*begin_list)->next)
{
previous = *begin_list;
while (previous->next != current)
previous = current->next;
previous->next = 0;
current->next = previous;
current = previous;
}
*begin_list = last;
}

24
ex10/ft_list.h

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/16 12:37:31 by emartine #+# #+# */
/* Updated: 2017/08/16 12:37:33 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
# define FT_LIST_H
typedef struct s_list
{
struct s_list *next;
void *data;
} t_list;
t_list *ft_create_elem(void *data);
#endif

27
ex10/ft_list_foreach_if.c

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list_foreach_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/17 15:57:20 by emartine #+# #+# */
/* Updated: 2017/08/17 16:02:27 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
void ft_list_foreach_if(t_list *begin_list, void (*f)(void *),
void *data_ref, int (*cmp)())
{
t_list *current;
current = begin_list;
while (current)
{
if (cmp(current->data, data_ref) == 0)
f(current->data);
current = current->next;
}
}
Loading…
Cancel
Save