-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_listF.c
More file actions
78 lines (69 loc) · 1.75 KB
/
linked_listF.c
File metadata and controls
78 lines (69 loc) · 1.75 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
70
71
72
73
74
75
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* linked_listF.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: melkarmi <melkarmi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/03 16:54:43 by melkarmi #+# #+# */
/* Updated: 2021/10/03 16:54:45 by melkarmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "philosophers.h"
void addback(t_philo **alst, t_philo *new)
{
t_philo *n;
n = *alst;
if (!new)
return ;
if (!*alst)
(*alst) = new;
else
{
while (n->next)
n = n->next;
n->next = new;
}
}
t_philo *new_philo(int content, t_data *data)
{
t_philo *new;
new = malloc(sizeof(t_philo));
if (new == NULL)
return (NULL);
new->id = content;
new->status = 0;
new->eatenmeals = 0;
new->data = data;
new->fork = 0;
new->fork1 = 0;
new->die = get_time();
new->next = NULL;
return (new);
}
t_fork *new_fork(int content)
{
t_fork *new;
new = malloc(sizeof(t_fork));
if (new == NULL)
return (NULL);
new->philo = content;
new->new_philo = 0;
new->next = NULL;
return (new);
}
void addbackf(t_fork **alst, t_fork *new)
{
t_fork *n;
n = *alst;
if (!new)
return ;
if (!*alst)
(*alst) = new;
else
{
while (n->next)
n = n->next;
n->next = new;
}
}