We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5bfc568 commit 7afe0d9Copy full SHA for 7afe0d9
024_swap_nodes_in_pairs/swap_nodes.c
@@ -15,16 +15,17 @@ static struct ListNode* swapPairs(struct ListNode* head)
15
dummy.next = head;
16
struct ListNode *prev = &dummy;
17
struct ListNode *p = dummy.next;
18
- struct ListNode *next = p->next;
19
- while (p != NULL && next != NULL) {
20
- prev->next = next;
21
- p->next = next->next;
22
- next->next = p;
+
+ while (p != NULL && p->next != NULL) {
+ struct ListNode *q = p->next;
+ /* deletion */
+ p->next = q->next;
23
+ /* insertion */
24
+ q->next = p;
25
+ prev->next = q;
26
+ /* iteration */
27
prev = p;
28
p = p->next;
- if (p != NULL) {
- next = p->next;
- }
29
}
30
return dummy.next;
31
0 commit comments