- Added shift and length operations for generic lists.

This commit is contained in:
ccremers 2004-08-09 21:44:16 +00:00
parent 01d914314e
commit ca4c0c8869
2 changed files with 28 additions and 0 deletions

View File

@ -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;
}

View File

@ -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