Skip to content

Commit

Permalink
Implement q_swap function
Browse files Browse the repository at this point in the history
Implement q_swap() to swap every two adjacent nodes
  • Loading branch information
aftuta85 committed Mar 20, 2024
1 parent 5a48488 commit 0f6c922
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ bool q_delete_dup(struct list_head *head)
/* Swap every two adjacent nodes */
void q_swap(struct list_head *head)
{
// https://leetcode.com/problems/swap-nodes-in-pairs/
struct list_head *curr = head->next;
while (curr != head && curr->next != head) {
list_move(curr, curr->next);
curr = curr->next;
}
}

/* Reverse elements in queue */
Expand Down

0 comments on commit 0f6c922

Please sign in to comment.