data_structures
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
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
list.h
list_new
t_list * list_new(const t_type *type)
Allocates memory and initializes an empty list.
Definition: list_new.c:16