54 lines
1.7 KiB
C
54 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_lstlast_bonus.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/21 12:03:16 by kcolin #+# #+# */
|
|
/* Updated: 2024/10/21 13:16:06 by kcolin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
t_list *ft_lstlast(t_list *lst)
|
|
{
|
|
t_list *current;
|
|
|
|
if (lst == NULL)
|
|
return (NULL);
|
|
current = lst;
|
|
while (current->next != NULL)
|
|
{
|
|
current = current->next;
|
|
}
|
|
return (current);
|
|
}
|
|
|
|
/*
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(void)
|
|
{
|
|
t_list *list;
|
|
t_list *new;
|
|
|
|
list = ft_lstnew("Hello There!");
|
|
printf("current:\t%p\n", list);
|
|
printf("content:\t%s\n", (char *)list->content);
|
|
printf("next:\t\t%p\n", list->next);
|
|
printf("length:\t%d\n", ft_lstsize(list));
|
|
new = ft_lstnew("New Element!");
|
|
ft_lstadd_front(&list, new);
|
|
printf("current:\t%p\n", list);
|
|
printf("content:\t%s\n", (char *)list->content);
|
|
printf("next:\t\t%p\n", list->next);
|
|
printf("length:\t%d\n", ft_lstsize(list));
|
|
printf("last:\t\t%p\n", ft_lstlast(list));
|
|
free(list->next);
|
|
free(list);
|
|
return (0);
|
|
}
|
|
*/
|