Skip to content

Commit

Permalink
Implement q_new function
Browse files Browse the repository at this point in the history
According to the materials from lab0 provided by the instructor, it's understood
that the definitions of NULL queue and Empty queue are different. An Empty queue
signifies that the queue points to a valid data structure (head). Therefore, when
implementing this method, I need to allocate a memory block for head using malloc
and then set the prev and next pointers of head to point to itself.
  • Loading branch information
aa860630 committed Feb 26, 2024
1 parent 2e70210 commit e930d05
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
/* Create an empty queue */
struct list_head *q_new()
{
return NULL;
struct list_head *head = malloc(sizeof(struct list_head));
head->next = head;
head->prev = head;
return head;
}

/* Free all storage used by queue */
Expand Down

0 comments on commit e930d05

Please sign in to comment.