Skip to content

Commit

Permalink
Implement q_reverse function
Browse files Browse the repository at this point in the history
Utilize `list_move` to move the `node` to the beginning of the `list`.
  • Loading branch information
zoo868e committed Feb 26, 2024
1 parent 06b4a06 commit 1124c5a
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 @@ -174,7 +174,14 @@ void q_swap(struct list_head *head)
}

/* Reverse elements in queue */
void q_reverse(struct list_head *head) {}
void q_reverse(struct list_head *head)
{
if (!head || list_empty(head))
return;
struct list_head *cur, *n;
list_for_each_safe (cur, n, head)
list_move(cur, head);
}

/* Reverse the nodes of the list k at a time */
void q_reverseK(struct list_head *head, int k)
Expand Down

0 comments on commit 1124c5a

Please sign in to comment.