Added functionality to get the size of the list
This commit is contained in:
@@ -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);
|
||||
|
||||
+19
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user