| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2023 | ||
| 3 | ** my_sort_list | ||
| 4 | ** File description: | ||
| 5 | ** Sorts a linked list | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "mylist.h" | ||
| 9 | |||
| 10 | ✗ | static void check_swap(linked_list_t **list, int (*cmp) ()) | |
| 11 | { | ||
| 12 | void *tmp; | ||
| 13 | |||
| 14 | ✗ | if ((*list)->prev != NULL && cmp((*list)->prev->data, (*list)->data) > 0) { | |
| 15 | ✗ | tmp = (*list)->prev->data; | |
| 16 | ✗ | (*list)->prev->data = (*list)->data; | |
| 17 | ✗ | (*list)->data = tmp; | |
| 18 | } | ||
| 19 | ✗ | } | |
| 20 | |||
| 21 | ✗ | void my_sort_list(linked_list_t **begin, int (*cmp) ()) | |
| 22 | { | ||
| 23 | ✗ | for (linked_list_t *list1 = *begin; list1 != NULL; list1 = list1->next) { | |
| 24 | ✗ | for (linked_list_t *list2 = (*begin)->next; | |
| 25 | ✗ | list2 != NULL; list2 = list2->next) { | |
| 26 | ✗ | check_swap(&list2, cmp); | |
| 27 | } | ||
| 28 | } | ||
| 29 | ✗ | } | |
| 30 |