Added functionality to get the size of the list

This commit is contained in:
amazing-username
2019-07-24 22:00:17 -04:00
parent d96758277a
commit fed1c1a091
2 changed files with 20 additions and 0 deletions
+1
View File
@@ -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
View File
@@ -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)
{