-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_helpers3_bonus.c
77 lines (68 loc) · 1.67 KB
/
function_helpers3_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* function_helpers3_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abazerou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/30 10:54:43 by abazerou #+# #+# */
/* Updated: 2023/06/02 12:14:00 by abazerou ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_freetab_bonus(t_v *v)
{
v->i = 0;
while (v->i < v->size)
{
free(v->s[v->i++]);
}
free(v->s);
}
int ft_lstsize(t_list *lst)
{
int count;
count = 0;
while (lst)
{
lst = lst->next;
count++;
}
return (count);
}
void ft_lstadd_back(t_list **alst, t_list *new)
{
t_list *p;
if (alst)
{
if ((*alst) == NULL)
(*alst) = new;
else
{
p = *alst;
while (p->next != NULL)
p = p->next;
p->next = new;
}
}
}
void ft_lstadd_front(t_list **alst, t_list *new)
{
if (new)
{
new->next = *alst;
*alst = new;
new = NULL;
}
}
t_list *ft_lstnew(int content, int j)
{
t_list *element;
element = (t_list *)malloc(sizeof(t_list));
if (!element)
return (NULL);
element->data = content;
element->index = j;
element->next = NULL;
return (element);
}