-
Notifications
You must be signed in to change notification settings - Fork 1
/
list2.c
61 lines (55 loc) · 1.77 KB
/
list2.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttshivhu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/27 10:28:40 by ttshivhu #+# #+# */
/* Updated: 2017/10/27 10:35:13 by ttshivhu ### ########.fr */
/* */
/* ************************************************************************** */
#include "expert.h"
static int in_list(t_expert *head, char alpha)
{
t_expert *current;
current = head;
while (current != NULL)
{
if (current->alpha == alpha)
return (1);
current = current->next;
}
return (0);
}
static int new_item(t_expert **head, char alpha, int f_facts, int status)
{
*head = malloc(sizeof(t_expert));
if (*head == NULL)
return (1);
(*head)->alpha = alpha;
(*head)->status = status;
(*head)->f_facts = f_facts;
(*head)->next = NULL;
return (1);
}
int add_item(t_expert **head, char alpha, int f_facts, int status)
{
t_expert *new_node;
if (*head == NULL)
return (new_item(head, alpha, f_facts, status));
else
{
if (!in_list(*head, alpha))
{
new_node = malloc(sizeof(t_expert));
new_node->alpha = alpha;
new_node->status = status;
new_node->f_facts = f_facts;
new_node->next = *head;
*head = new_node;
return (1);
}
}
return (0);
}