aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/list.c15
-rw-r--r--src/list.h2
-rw-r--r--tests/list.c6
3 files changed, 17 insertions, 6 deletions
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 ) {
diff --git a/src/list.h b/src/list.h
index 71594ad..1359955 100644
--- a/src/list.h
+++ b/src/list.h
@@ -20,6 +20,6 @@ int list_add( list_element_t** _root, void* _data );
int list_sort ( list_element_t** _root );
-int list_length ( list_element_t* _root );
+int list_length ( list_element_t** _root );
void* list_pop_front ( list_element_t** _root );
diff --git a/tests/list.c b/tests/list.c
index 25fa323..722568b 100644
--- a/tests/list.c
+++ b/tests/list.c
@@ -20,14 +20,14 @@ START_TEST ( test_list_all ) {
/* Not implemented
list_sort(&root);
-
- ck_assert_int_eq( list_length(root), 9 );
*/
+ ck_assert_int_ne( list_sort(&root), 0 );
+ ck_assert_int_eq( list_length(&root), 9 );
for ( i=0; i<=8; i++ )
ck_assert_int_eq(*(int*)list_pop_front(&root), i);
- /*ck_assert_int_eq( list_length(root), 0 );*/
+ ck_assert_int_eq( list_length(&root), 0 );
} END_TEST