Skip to content

Commit a8e6d35

Browse files
committed
Implement q_swap using q_reverseK with k=2
Previously, q_swap was a placeholder and did nothing. Now it correctly swaps adjacent nodes by calling q_reverseK with k=2, as swapping pairs is a special case of k-group reversal. Change-Id: Ia35f40364457b6877c80764452a6cf3409dafd78
1 parent 341fbed commit a8e6d35

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

queue.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ bool q_delete_dup(struct list_head *head)
158158
void q_swap(struct list_head *head)
159159
{
160160
// https://leetcode.com/problems/swap-nodes-in-pairs/
161+
q_reverseK(head, 2);
161162
}
162163

163164
/* Reverse elements in queue */

0 commit comments

Comments
 (0)