-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstlast.c
More file actions
55 lines (44 loc) · 846 Bytes
/
ft_lstlast.c
File metadata and controls
55 lines (44 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Returns the last node of the list.
#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>
void print_list(t_list *lst)
{
while (lst)
{
printf("%p", (void *)lst);
printf("-> %s\n", (char *)lst->content);
lst = lst->next;
}
printf("NULL\n");
}
int main(void)
{
t_list *node1 = ft_lstnew("One");
t_list *node2 = ft_lstnew("Two");
t_list *node3 = ft_lstnew("Three");
node1->next = node2;
node2->next = node3;
printf("Linked List: \n");
print_list(node1);
t_list *last_node = ft_lstlast(node1);
printf("Last node: %s\n", (char *)last_node->content);
while (node1)
{
t_list *temp = node1;
node1 = node1->next;
free(temp);
}
return (0);
}
*/