blob: e6a9460c99b5f9575fd8c67784b6c512b0625130 (
plain)
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
|
#include <stdlib.h>
#include "header.h"
t_flist *list_new(t_pformat *content)
{
t_flist *lst;
if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL)
return NULL;
lst->content = content;
lst->next = NULL;
return (lst);
}
void *list_destroy(t_flist **lst)
{
if (lst == NULL)
return (NULL);
while (*lst != NULL)
list_pop_front(lst);
return (NULL);
}
void list_push_front(t_flist **lst, t_flist *new)
{
if (lst == NULL || new == NULL)
return ;
new->next = *lst;
*lst = new;
}
void list_pop_front(t_flist **lst)
{
t_flist *tmp;
if (lst == NULL || *lst == NULL)
return ;
tmp = (*lst)->next;
free((*lst)->content);
free(*lst);
*lst = tmp;
}
void list_reverse(t_flist **lst)
{
t_flist *cursor;
t_flist *prev;
t_flist *tmp;
prev = NULL;
cursor = *lst;
while (cursor != NULL)
{
tmp = cursor;
cursor->next = prev;
prev = cursor;
cursor = tmp->next;
}
*lst = prev;
}
|