data_structures
src
data_structures
list
list_copy.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* list_copy.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/22 10:07:52 by unite #+# #+# */
10
/* Updated: 2020/09/07 22:02:11 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
list.h
"
15
16
t_list
*
list_copy
(
const
t_list
*alst)
17
{
18
t_list
*copy;
19
t_link
*link;
20
21
copy =
list_new
(alst->
type
);
22
link = alst->
head
;
23
while
(link)
24
{
25
list_add_last
(copy, link->
content
);
26
link = link->
next
;
27
}
28
return
(copy);
29
}
list_copy
t_list * list_copy(const t_list *alst)
Copies an list and all it contents.
Definition:
list_copy.c:16
s_link::content
void * content
The content.
Definition:
list.h:36
list_add_last
void list_add_last(t_list *alst, const void *data)
Adds a copy of the specified element at the back of this list.
Definition:
list_add_last.c:16
s_list::head
t_link * head
The first link.
Definition:
list.h:56
s_list
Doubly-linked list of generic items.
Definition:
list.h:54
s_list::type
const t_type * type
The type of items in this list.
Definition:
list.h:59
s_link::next
struct s_link * next
The next link.
Definition:
list.h:37
list.h
list_new
t_list * list_new(const t_type *type)
Allocates memory and initializes an empty list.
Definition:
list_new.c:16
s_link
A link in a doubly-linked list.
Definition:
list.h:34
Generated by
1.8.16