-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_prepend.c
executable file
·60 lines (56 loc) · 2.08 KB
/
list_prepend.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_prepend.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_prepend -- adds a new element to the beginning of a list.
**
** SYNOPSIS
** #include <../libft.h>
**
** t_list *
** list_prepend(t_list **head, const void *item);
**
** PARAMETERS
**
** t_list **head Pointer to a pointer to the
** first element of a list.
**
** const void *item Data that will be stored in
** the new list element.
**
** DESCRIPTION
** Creates a new list element, storing 'item' as its item, then
** adds the element to the front of the list (that (*head) points
** to).
**
** If the list does not exist the newly created element is made
** to be the first element of the list and (*head) is made to
** point to it.
**
** (*head) is made to point to the first element of the list.
**
** RETURN VALUES
** Returns 0 if successful; otherwise -1.
*/
#include "../Includes/list.h"
int list_prepend(t_list **head, const void *item)
{
t_list *new_elem;
if (head && (new_elem = list_newelem(item)))
{
if (*head)
new_elem->next = (*head);
(*head) = new_elem;
return (0);
}
return (-1);
}