-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_last_elem.c
executable file
·49 lines (46 loc) · 1.61 KB
/
list_last_elem.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_last_elem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/25 13:30:15 by akharrou #+# #+# */
/* Updated: 2019/03/04 13:17:20 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** list_last_elem -- get the last element of a list.
**
** SYNOPSIS
** #include <../libft.h>
**
** t_list *
** list_last_elem(t_list *head);
**
** PARAMETERS
**
** t_list *head Pointer to the first element of
** a list.
**
** DESCRIPTION
** Traverses the list until it finds the last element of
** the list then returns a pointer to it.
**
** RETURN VALUES
** If successful returns a pointer to the last element of
** list.
*/
#include "../Includes/stdlib_42.h"
#include "../Includes/list.h"
t_list *list_last_elem(t_list *head)
{
if (head)
{
while (head->next)
head = head->next;
return (head);
}
return (NULL);
}