From 87bce91050b56915dcf5964f6f66d5f47299e7f3 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 29 Oct 2019 01:57:41 +0100 Subject: Reworking, binary flags, extract advance - Binary flags attribute instead of multiple bool - Extract doesnst strdup fmt each time, just advance the current pointer - In parsing push front then reverse - Moved some functions to libf --- list.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'list.c') diff --git a/list.c b/list.c index e6a9460..b87c69a 100644 --- a/list.c +++ b/list.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:14:50 by cacharle #+# #+# */ +/* Updated: 2019/10/29 00:14:51 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include #include "header.h" @@ -6,7 +18,7 @@ t_flist *list_new(t_pformat *content) t_flist *lst; if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL) - return NULL; + return (NULL); lst->content = content; lst->next = NULL; return (lst); @@ -21,7 +33,6 @@ void *list_destroy(t_flist **lst) return (NULL); } - void list_push_front(t_flist **lst, t_flist *new) { if (lst == NULL || new == NULL) @@ -42,20 +53,16 @@ void list_pop_front(t_flist **lst) *lst = tmp; } -void list_reverse(t_flist **lst) +t_flist *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; + if (lst == NULL) + return (NULL); + if (lst->next == NULL) + return (lst); + tmp = list_reverse(lst->next); + lst->next->next = lst; + lst->next = NULL; + return (tmp); } -- cgit