Skip to content

Commit 7ab2afb

Browse files
committed
Implement q_insert_tail
Previously, q_insert_tail() was a placeholder and did nothing. Now it correctly inserts a new element at the tail of the queue, allocating memory and linking it properly.
1 parent 71928ec commit 7ab2afb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

queue.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ bool q_insert_head(struct list_head *head, char *s)
5353
/* Insert an element at tail of queue */
5454
bool q_insert_tail(struct list_head *head, char *s)
5555
{
56+
if (!head)
57+
return false;
58+
element_t *new_elem = malloc(sizeof(element_t));
59+
if (!new_elem)
60+
return false;
61+
new_elem->value = s;
62+
list_add_tail(&new_elem->list, head);
5663
return true;
5764
}
5865

0 commit comments

Comments
 (0)