From ca4c0c886967d3d7ed4ddd42c108d48e9932ca6b Mon Sep 17 00:00:00 2001 From: ccremers Date: Mon, 9 Aug 2004 21:44:16 +0000 Subject: [PATCH] - Added shift and length operations for generic lists. --- src/list.c | 26 ++++++++++++++++++++++++++ src/list.h | 2 ++ 2 files changed, 28 insertions(+) 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