-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlists_op.c
100 lines (89 loc) · 1.98 KB
/
lists_op.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lists_op.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fsalvett <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 12:08:35 by fsalvett #+# #+# */
/* Updated: 2023/03/31 12:10:36 by fsalvett ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void list_free(t_list **head)
{
t_list *temp;
if ((*head)->next == NULL)
{
free(head);
}
while (*head != NULL)
{
temp = *head;
*head = (*head)->next;
free(temp);
}
}
int list_size(t_list *head)
{
size_t i;
t_list *tmp;
tmp = head;
i = 0;
while (tmp)
{
tmp = tmp->next;
i++;
}
return (i);
}
void list_add_end(t_list **head, int value)
{
t_list *new;
t_list *temp;
new = malloc(sizeof(t_list));
new->value = value;
new->next = NULL;
temp = *head;
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = new;
}
void list_populate(t_list **head, char **argv, int argc)
{
int i;
int temp;
temp = 0;
i = 1;
if (i == 1)
{
*head = malloc(sizeof(t_list));
(*head)->value = atoi(argv[i]);
(*head)->next = NULL;
i++;
}
while (i < argc)
{
temp = atoi(argv[i]);
if (check_doubles(temp, *head) == 0)
{
write(1, "Error\n", 6);
exit(1);
}
list_add_end(head, temp);
i++;
}
}
void list_print(t_list **head)
{
t_list *temp;
temp = *head;
while (temp != NULL)
{
ft_printf("%d ", temp->value);
temp = temp->next;
}
ft_printf("\n");
}