-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_extend.c
executable file
·68 lines (64 loc) · 2.42 KB
/
list_extend.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
58
59
60
61
62
63
64
65
66
67
68
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_extend.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/22 19:19:47 by akharrou #+# #+# */
/* Updated: 2019/03/04 13:17:20 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** list_extend -- appends multiple new elements to a list.
**
** SYNOPSIS
** #include <../libft.h>
**
** int
** list_extend(t_list **head, const void **item_vector);
**
** PARAMETERS
**
** t_list **head Pointer to a pointer to the
** first element of a list
** (that said, it could be a
** pointer to any element of
** a list since the list will
** be traversed in any case).
**
** const void **item_vector Vector containing items
** to add to the end of the
** list.
**
** DESCRIPTION
** Creates new list elements using the items in the item
** vector and adds the newly created list elements to the
** end of the list (that (*head) points to).
**
** (*head) stays pointing to whatever it originally pointed to.
**
** RETURN VALUES
** Returns 0 if successful; otherwise -1.
*/
#include "../Includes/list.h"
int list_extend(t_list **head, const void **item_vector)
{
t_list *original_head;
if (head && item_vector)
{
if (!(*head))
(*head) = list_newelem(*item_vector++);
original_head = (*head);
while (*item_vector)
{
if ((list_append_tail(head, *item_vector)) == -1)
return (-1);
item_vector++;
}
(*head) = original_head;
return (0);
}
return (-1);
}