diff --git a/include/klist.h b/include/klist.h index 125935d..67228cb 100644 --- a/include/klist.h +++ b/include/klist.h @@ -3,6 +3,7 @@ struct node* init_list(void*, size_t); int is_list_init(struct node**); +int list_size(struct node**); void insert_at_begin(struct node**, void*, size_t); void insert_at_end(struct node**, void*, size_t); diff --git a/src/klist.c b/src/klist.c index 59fbb68..c377f8e 100644 --- a/src/klist.c +++ b/src/klist.c @@ -22,6 +22,25 @@ int is_list_init(struct node **list) else return 0; } +int list_size(struct node **list) +{ + int count = 0; + struct node *tmp = *list; + + struct node *in_tmp = NULL; + + while (tmp != NULL || tmp->next != NULL) { + in_tmp = tmp; + tmp = tmp->next; + + ++count; + + if (tmp == NULL) + break; + } + + return count; +} void insert_at_begin(struct node **list, void *val, size_t val_size) {