Skip to content

Commit d1b2056

Browse files
committed
Implement q_size function
The q_size function returns the number of nodes in the queue. Change-Id: I4fc028ef627bff46f84e77bbf042b3e51a6f02e4
1 parent 8316fb7 commit d1b2056

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

queue.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ element_t *q_remove_tail(struct list_head *head, char *sp, size_t bufsize)
117117
/* Return number of elements in queue */
118118
int q_size(struct list_head *head)
119119
{
120-
return -1;
120+
if (!head)
121+
return 0;
122+
123+
int size = 0;
124+
struct list_head *node;
125+
126+
list_for_each (node, head)
127+
size++;
128+
129+
return size;
121130
}
122131

123132
/* Delete the middle node in queue */

0 commit comments

Comments
 (0)