Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_push_back | ||
4 | ** File description: | ||
5 | ** Adds a node at the end of a linked list | ||
6 | */ | ||
7 | /** | ||
8 | * @file my_push_back.c | ||
9 | * @brief The file containing the my_push_back function | ||
10 | * @author Nicolas TORO | ||
11 | */ | ||
12 | |||
13 | #include "mylist.h" | ||
14 | |||
15 | 25388 | void my_push_back(node_t **begin, void *data, type_t type) | |
16 | { | ||
17 | 25388 | node_t *new = malloc(sizeof(node_t)); | |
18 | 25388 | node_t *tmp = *begin; | |
19 | |||
20 | 25388 | new->data = data; | |
21 | 25388 | new->type = type; | |
22 | 25388 | new->next = NULL; | |
23 |
2/2✓ Branch 0 taken 3763 times.
✓ Branch 1 taken 21625 times.
|
25388 | if (*begin == NULL) { |
24 | 3763 | new->prev = NULL; | |
25 | 3763 | *begin = new; | |
26 | 3763 | return; | |
27 | } | ||
28 |
2/2✓ Branch 0 taken 9375790 times.
✓ Branch 1 taken 21625 times.
|
9397415 | while (tmp->next != NULL) |
29 | 9375790 | tmp = tmp->next; | |
30 | 21625 | tmp->next = new; | |
31 | 21625 | new->prev = tmp; | |
32 | } | ||
33 |