diff --git a/queue.c b/queue.c index 723364bf9..be07211e7 100644 --- a/queue.c +++ b/queue.c @@ -144,7 +144,19 @@ 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 *curr = head, *nxt = NULL; + while (nxt != head) { + nxt = curr->next; + curr->next = curr->prev; + curr->prev = nxt; + curr = nxt; + } +} /* Reverse the nodes of the list k at a time */ void q_reverseK(struct list_head *head, int k)