aboutsummaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-28 04:15:16 +0100
committerCharles <sircharlesaze@gmail.com>2019-10-28 04:15:16 +0100
commitf6ee1462e26d723cf5d53157eadaff2804d18c3a (patch)
tree366ba00a09afe4b7d21c55ee25fd98030b2cd5a5 /list.c
parentfeb71e200972bb78fe86130629ef040ef80811a7 (diff)
downloadft_printf-f6ee1462e26d723cf5d53157eadaff2804d18c3a.tar.gz
ft_printf-f6ee1462e26d723cf5d53157eadaff2804d18c3a.tar.bz2
ft_printf-f6ee1462e26d723cf5d53157eadaff2804d18c3a.zip
reformed pformat struct, rename t_flist
Diffstat (limited to 'list.c')
-rw-r--r--list.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/list.c b/list.c
index f2b375c..e6a9460 100644
--- a/list.c
+++ b/list.c
@@ -1,18 +1,18 @@
#include <stdlib.h>
#include "header.h"
-t_pformat_list *list_new(t_pformat *content)
+t_flist *list_new(t_pformat *content)
{
- t_pformat_list *lst;
+ t_flist *lst;
- if ((lst = (t_pformat_list*)malloc(sizeof(t_pformat_list))) == NULL)
+ if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL)
return NULL;
lst->content = content;
lst->next = NULL;
return (lst);
}
-void *list_destroy(t_pformat_list **lst)
+void *list_destroy(t_flist **lst)
{
if (lst == NULL)
return (NULL);
@@ -22,7 +22,7 @@ void *list_destroy(t_pformat_list **lst)
}
-void list_push_front(t_pformat_list **lst, t_pformat_list *new)
+void list_push_front(t_flist **lst, t_flist *new)
{
if (lst == NULL || new == NULL)
return ;
@@ -30,26 +30,9 @@ void list_push_front(t_pformat_list **lst, t_pformat_list *new)
*lst = new;
}
-void list_push_back(t_pformat_list **lst, t_pformat_list *new)
+void list_pop_front(t_flist **lst)
{
- 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;
+ t_flist *tmp;
if (lst == NULL || *lst == NULL)
return ;
@@ -58,3 +41,21 @@ void list_pop_front(t_pformat_list **lst)
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;
+}