diff options
Diffstat (limited to 'linked_list.c')
-rw-r--r-- | linked_list.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/linked_list.c b/linked_list.c index 3c694be..0eeb19b 100644 --- a/linked_list.c +++ b/linked_list.c @@ -62,6 +62,19 @@ void cleanup_linked_list(linked_list *node) { } } +void **linked_list_to_array(linked_list *node) { + void **arr = calloc(linked_list_size(get_tail(node))+1, sizeof(void *)); + int i = 0; + + for (linked_list *n = get_head(node); n != NULL; n = n->next, ++i) { + arr[i] = n->data; + } + + arr[i] = NULL; + + return arr; +} + int linked_list_size(linked_list *tail) { int i = 0; for (linked_list *node = tail; node != NULL; node = node->prev, ++i); |