| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2023 | ||
| 3 | ** my_sort_list | ||
| 4 | ** File description: | ||
| 5 | ** Sorts a linked list | ||
| 6 | */ | ||
| 7 | /** | ||
| 8 | * @file my_sort_list.c | ||
| 9 | * @brief The file containing the my_sort_list function | ||
| 10 | * @author Nicolas TORO | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "mylist.h" | ||
| 14 | |||
| 15 | 6 | static void check_swap(node_t **list, int (*cmp)()) | |
| 16 | { | ||
| 17 | void *tmp; | ||
| 18 | |||
| 19 |
3/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 5 times.
|
6 | if ((*list)->prev != NULL && cmp((*list)->prev->data, (*list)->data) > 0) { |
| 20 | 1 | tmp = (*list)->prev->data; | |
| 21 | 1 | (*list)->prev->data = (*list)->data; | |
| 22 | 1 | (*list)->data = tmp; | |
| 23 | } | ||
| 24 | 6 | } | |
| 25 | |||
| 26 | 1 | void my_sort_list(node_t **begin, int (*cmp)()) | |
| 27 | { | ||
| 28 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (node_t *list1 = *begin; list1 != NULL; list1 = list1->next) { |
| 29 | 3 | for (node_t *list2 = (*begin)->next; | |
| 30 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | list2 != NULL; list2 = list2->next) { |
| 31 | 6 | check_swap(&list2, cmp); | |
| 32 | } | ||
| 33 | } | ||
| 34 | 1 | } | |
| 35 |