71 lines
1.7 KiB
C
71 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* t_slist.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/01/09 18:46:50 by apommier #+# #+# */
|
|
/* Updated: 2022/01/09 18:46:50 by apommier ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "push_swap.h"
|
|
|
|
t_slist *new_slist(void *content)
|
|
{
|
|
t_slist *new;
|
|
|
|
new = (t_slist *)malloc(sizeof(t_slist));
|
|
if (!new)
|
|
return (0);
|
|
new->action = content;
|
|
new->next = 0;
|
|
return (new);
|
|
}
|
|
|
|
void s_lstclear(t_slist **lst)
|
|
{
|
|
t_slist *chr;
|
|
|
|
chr = *lst;
|
|
while (*lst)
|
|
{
|
|
chr = (*lst)->next;
|
|
free(*lst);
|
|
*lst = chr;
|
|
}
|
|
lst = 0;
|
|
}
|
|
|
|
void s_lstadd_back(t_slist **alst, t_slist *new)
|
|
{
|
|
if (*alst == 0)
|
|
*alst = new;
|
|
else
|
|
s_lstlast(*alst)->next = new;
|
|
new->next = 0;
|
|
}
|
|
|
|
t_slist *s_lstlast(t_slist *lst)
|
|
{
|
|
if (!lst)
|
|
return (0);
|
|
while (lst->next)
|
|
lst = lst->next;
|
|
return (lst);
|
|
}
|
|
|
|
void printf_slist(t_slist *start)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (start)
|
|
{
|
|
i++;
|
|
ft_putendl_fd((char *)start->action, 1);
|
|
start = start->next;
|
|
}
|
|
}
|