-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_popleft.c
executable file
·59 lines (55 loc) · 2.02 KB
/
list_popleft.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_popleft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/22 19:31:05 by akharrou #+# #+# */
/* Updated: 2019/03/04 13:17:20 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** list_popleft -- removes the first element of a list and returns
** the item it contains.
**
** SYNOPSIS
** #include <../libft.h>
**
** void *
** list_popleft(t_list **head);
**
** PARAMETERS
**
** t_list **head Pointer to a pointer to the first
** element of a list.
**
** DESCRIPTION
** Removes and frees the first element of the list, that (*head)
** points to, updates (*head) to point to the new first element of
** the list and returns the item that the first element contained.
**
** If the list had a single element, (*head), after popping the
** first element, will be made to point to NULL.
**
** RETURN VALUES
** If successful returns the item from the popped element of the
** list; otherwise NULL.
*/
#include "../Includes/stdlib_42.h"
#include "../Includes/list.h"
void *list_popleft(t_list **head)
{
void *item;
t_list *tmp;
if (head && (*head))
{
item = (*head)->item;
tmp = (*head);
(*head) = (*head)->next;
free(tmp);
return (item);
}
return (NULL);
}