Skip to content

Commit

Permalink
Implement q_size function
Browse files Browse the repository at this point in the history
Implement q_size() to get the size of the queue.
  • Loading branch information
aftuta85 committed Mar 16, 2024
1 parent dd6a761 commit d69e38b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ element_t *q_remove_tail(struct list_head *head, char *sp, size_t bufsize)
/* Return number of elements in queue */
int q_size(struct list_head *head)
{
return -1;
if (!head)
return 0;

int size = 0;
struct list_head *curr;
list_for_each (curr, head)
size++;
return size;
}

/* Delete the middle node in queue */
Expand Down

0 comments on commit d69e38b

Please sign in to comment.