-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
69 lines (60 loc) · 1.69 KB
/
Copy pathlist.c
File metadata and controls
69 lines (60 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamali <mamali@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/26 16:17:54 by mamali #+# #+# */
/* Updated: 2021/09/27 16:28:47 by mamali ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
t_fork *ft_lstlastfork(t_fork *lst)
{
t_fork *tmp;
tmp = lst;
if (!tmp)
return (lst);
while (tmp->next)
tmp = tmp->next;
return (tmp);
}
t_philo *ft_lstlast(t_philo *lst)
{
t_philo *tmp;
tmp = lst;
if (!tmp)
return (lst);
while (tmp->next)
tmp = tmp->next;
return (tmp);
}
void add_back_fork(t_fork **head, t_fork *new_philo)
{
new_philo->next = NULL;
if (!head || !*head)
*head = new_philo;
else
ft_lstlastfork(*head)->next = new_philo;
}
void add_back(t_philo **head, t_philo *new_philo)
{
new_philo->next = NULL;
if (!head || !*head)
*head = new_philo;
else
ft_lstlast(*head)->next = new_philo;
}
t_fork *get_fork(t_data *data, int id)
{
t_fork *fork;
fork = data->fork;
while (fork)
{
if (fork->philo == id)
return (fork);
fork = fork->next;
}
return (NULL);
}