- Added shift and length operations for generic lists.
This commit is contained in:
parent
01d914314e
commit
ca4c0c8869
26
src/list.c
26
src/list.c
@ -241,3 +241,29 @@ list_destroy (List list)
|
|||||||
free (node);
|
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;
|
||||||
|
}
|
||||||
|
@ -21,5 +21,7 @@ int in_list (List list, const void *data);
|
|||||||
int list_iterate (List list, int (*func) ());
|
int list_iterate (List list, int (*func) ());
|
||||||
List list_duplicate (List list);
|
List list_duplicate (List list);
|
||||||
void list_destroy (List list);
|
void list_destroy (List list);
|
||||||
|
List list_shift (List list, int n);
|
||||||
|
int list_length (List list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user