From 13293d178731bba7d77123e57bc08925d285d522 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 21 Sep 2021 21:57:26 +0200 Subject: list: add length and tests --- src/list.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/list.c') diff --git a/src/list.c b/src/list.c index 133637b..226985e 100644 --- a/src/list.c +++ b/src/list.c @@ -28,8 +28,19 @@ int list_sort ( list_element_t** _root ) { return -1; } -int list_length ( list_element_t* _root ) { - return -1; +int list_length ( list_element_t** _root ) { + list_element_t** iter = _root; + int ret = 0; + + if( !_root ) + return -1; + + while(*iter) { + ret ++; + iter = & (*iter)->next; + } + + return ret; } void* list_pop_front ( list_element_t** _root ) { -- cgit v1.2.3