-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_merge.c
executable file
·57 lines (53 loc) · 1.81 KB
/
list_merge.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
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_merge.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/22 19:33:34 by akharrou #+# #+# */
/* Updated: 2019/03/04 13:17:20 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** list_merge -- append one list to the end of another.
**
** SYNOPSIS
** #include <../libft.h>
**
** int
** list_merge(t_list **dest, t_list *src);
**
** PARAMETERS
**
** t_list **dest Pointer to a pointer to a
** destination list.
**
** t_list *src Pointer to a list that is
** that will be appended to
** the (*dest) list.
**
** DESCRIPTION
** Appends the (*dest) list to the end of the 'src' list.
**
** RETURN VALUES
** Returns 0 if successful; otherwise -1.
*/
#include "../Includes/list.h"
int list_merge(t_list **dest, t_list *src)
{
t_list *last;
if (!dest || (!(*dest) && !src))
return (-1);
else if (!(*dest) && src)
(*dest) = src;
else
{
last = list_last_elem(*dest);
if (!last)
return (-1);
last->next = src;
}
return (0);
}