diff options
Diffstat (limited to 'src/sp_list.c')
| -rw-r--r-- | src/sp_list.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/sp_list.c b/src/sp_list.c index 2a9d680..447f479 100644 --- a/src/sp_list.c +++ b/src/sp_list.c | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #include "php_snuffleupagus.h" | 4 | #include "php_snuffleupagus.h" |
| 5 | 5 | ||
| 6 | void sp_list_free(sp_list_node *node) { | 6 | void sp_list_free(sp_list_node *node) { |
| 7 | while(node) { | 7 | while (node) { |
| 8 | sp_list_node *tmp = node->next; | 8 | sp_list_node *tmp = node->next; |
| 9 | pefree(node, 1); | 9 | pefree(node, 1); |
| 10 | node = tmp; | 10 | node = tmp; |
| @@ -18,7 +18,8 @@ sp_list_node *sp_list_new() { | |||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | // Thanks to https://en.wikipedia.org/wiki/Insertion_sort :> | 20 | // Thanks to https://en.wikipedia.org/wiki/Insertion_sort :> |
| 21 | sp_list_node *sp_list_sort(sp_list_node *pList, int (*cmp_func)(sp_list_node *, sp_list_node *)) { | 21 | sp_list_node *sp_list_sort(sp_list_node *pList, |
| 22 | int (*cmp_func)(sp_list_node *, sp_list_node *)) { | ||
| 22 | sp_list_node *head = NULL; | 23 | sp_list_node *head = NULL; |
| 23 | 24 | ||
| 24 | if (pList == NULL || pList->next == NULL) { | 25 | if (pList == NULL || pList->next == NULL) { |
| @@ -33,12 +34,12 @@ sp_list_node *sp_list_sort(sp_list_node *pList, int (*cmp_func)(sp_list_node *, | |||
| 33 | } else { | 34 | } else { |
| 34 | sp_list_node *p = head; | 35 | sp_list_node *p = head; |
| 35 | while (p != NULL) { | 36 | while (p != NULL) { |
| 36 | if (p->next == NULL || 0 > cmp_func(current, p->next)) { | 37 | if (p->next == NULL || 0 > cmp_func(current, p->next)) { |
| 37 | current->next = p->next; | 38 | current->next = p->next; |
| 38 | p->next = current; | 39 | p->next = current; |
| 39 | break; | 40 | break; |
| 40 | } | 41 | } |
| 41 | p = p->next; | 42 | p = p->next; |
| 42 | } | 43 | } |
| 43 | } | 44 | } |
| 44 | } | 45 | } |
