diff --git a/src/list.c b/src/list.c index 0badd3c..5e85635 100644 --- a/src/list.c +++ b/src/list.c @@ -241,3 +241,29 @@ list_destroy (List list) free (node); } } + +//! Shift n positions to the right +List +list_shift (List list, int n) +{ + while (n > 0 && list != NULL) + { + list = list->next; + n--; + } + return list; +} + +//! Determine length of list from this point onwards +int +list_length (List list) +{ + int n; + + while (list != NULL) + { + n++; + list = list->next; + } + return n; +} diff --git a/src/list.h b/src/list.h index afbcd0b..1cabe72 100644 --- a/src/list.h +++ b/src/list.h @@ -21,5 +21,7 @@ int in_list (List list, const void *data); int list_iterate (List list, int (*func) ()); List list_duplicate (List list); void list_destroy (List list); +List list_shift (List list, int n); +int list_length (List list); #endif