ft_lstlast: initial implementation
This commit is contained in:
parent
7acdc05a62
commit
a872beadb9
3 changed files with 57 additions and 3 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
||||||
# Updated: 2024/10/21 11:49:58 by kcolin ### ########.fr #
|
# Updated: 2024/10/21 12:06:41 by kcolin ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -49,7 +49,8 @@ SOURCES = ft_isalpha.c \
|
||||||
OBJECTS = $(SOURCES:.c=.o)
|
OBJECTS = $(SOURCES:.c=.o)
|
||||||
BONUS_SOURCES = ft_lstnew_bonus.c \
|
BONUS_SOURCES = ft_lstnew_bonus.c \
|
||||||
ft_lstadd_front_bonus.c \
|
ft_lstadd_front_bonus.c \
|
||||||
ft_lstsize_bonus.c
|
ft_lstsize_bonus.c \
|
||||||
|
ft_lstlast_bonus.c
|
||||||
BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o)
|
BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
|
|
||||||
52
ft_lstlast_bonus.c
Normal file
52
ft_lstlast_bonus.c
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstlast_bonus.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/10/21 12:03:16 by kcolin #+# #+# */
|
||||||
|
/* Updated: 2024/10/21 12:04:50 by kcolin ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstlast(t_list *lst)
|
||||||
|
{
|
||||||
|
t_list *current;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
*/
|
||||||
3
libft.h
3
libft.h
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */
|
/* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */
|
||||||
/* Updated: 2024/10/21 11:11:02 by kcolin ### ########.fr */
|
/* Updated: 2024/10/21 12:11:28 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -72,5 +72,6 @@ typedef struct s_list
|
||||||
t_list *ft_lstnew(void *content);
|
t_list *ft_lstnew(void *content);
|
||||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||||
int ft_lstsize(t_list *lst);
|
int ft_lstsize(t_list *lst);
|
||||||
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue