aboutsummaryrefslogtreecommitdiff
path: root/list.c
blob: f2b375c6d118079057efe08c8d56da483dac3b73 (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
#include <stdlib.h>
#include "header.h"

t_pformat_list				*list_new(t_pformat *content)
{
	t_pformat_list	*lst;

	if ((lst = (t_pformat_list*)malloc(sizeof(t_pformat_list))) == NULL)
		return NULL;
	lst->content = content;
	lst->next = NULL;
	return (lst);
}

void						*list_destroy(t_pformat_list **lst)
{
	if (lst == NULL)
		return (NULL);
	while (*lst != NULL)
		list_pop_front(lst);
	return (NULL);
}


void						list_push_front(t_pformat_list **lst, t_pformat_list *new)
{
	if (lst == NULL || new == NULL)
		return ;
	new->next = *lst;
	*lst = new;
}

void						list_push_back(t_pformat_list **lst, t_pformat_list *new)
{
	t_pformat_list	*cursor;

	if (lst == NULL || new == NULL)
		return ;
	if (*lst == NULL)
	{
		*lst = new;
		return ;
	}
	cursor = *lst;
	while (cursor->next != NULL)
		cursor = cursor->next;
	cursor->next = new;
}

void						list_pop_front(t_pformat_list **lst)
{
	t_pformat_list	*tmp;

	if (lst == NULL || *lst == NULL)
		return ;
	tmp = (*lst)->next;
	free((*lst)->content);
	free(*lst);
	*lst = tmp;
}